<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('stage_academy_users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('country');
            $table->string('province');
            $table->string('gender');
            $table->string('phone')->unique();
            $table->string('password');
            $table->string('source_type')->default('admin');
            $table->timestamp('password_reset_at')->nullable();
            $table->timestamps();
        });

        Schema::create('stage_academy_user_courses', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('stage_academy_users')->onDelete('cascade');
            $table->foreignId('course_id')->constrained('stage_academy_courses')->onDelete('cascade');
            $table->timestamps();

            $table->unique(['user_id', 'course_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('stage_academy_user_courses');
        Schema::dropIfExists('stage_academy_users');
    }
};
