<?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
    {
        if (Schema::hasTable('stage_academy_activations')) {
            return;
        }

        Schema::create('stage_academy_activations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('stage_academy_users')->cascadeOnDelete();
            $table->foreignId('course_id')->constrained('stage_academy_courses')->cascadeOnDelete();
            $table->unsignedInteger('price');
            $table->string('payment_method');
            $table->string('invoice_number')->nullable()->unique();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

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

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