<?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('remplacements', function (Blueprint $table) {
            $table->id();
            $table->foreignId('mission_id')->constrained('missions')->cascadeOnDelete();
            $table->foreignId('candidat_remplace_id')->constrained('candidats');
            $table->foreignId('candidat_remplacant_id')->constrained('candidats');
            $table->foreignId('ordonne_par')->nullable()->constrained('users')->nullOnDelete();
            $table->date('date_remplacement')->notNull();
            $table->text('motif')->nullable();
            $table->enum('statut', ['propose', 'accepte', 'actif', 'termine'])->default('propose');
            $table->timestamps();
        });
    }

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