<?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::table('training_programs', function (Blueprint $table) {
            $table->foreignId('default_trainer_id')->nullable()->after('branch_id')->constrained('users')->nullOnDelete();
            $table->index(['academy_id', 'default_trainer_id']);
        });
    }

    public function down(): void
    {
        Schema::table('training_programs', function (Blueprint $table) {
            $table->dropForeign(['default_trainer_id']);
            $table->dropIndex(['academy_id', 'default_trainer_id']);
            $table->dropColumn('default_trainer_id');
        });
    }
};
