<?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('candidats', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();
            $table->string('reference', 20)->unique()->notNull();
            $table->string('nom', 100)->notNull();
            $table->string('prenom', 100)->notNull();
            $table->date('date_naissance')->nullable();
            $table->enum('sexe', ['femme', 'homme'])->nullable();
            $table->string('nationalite', 100)->nullable();
            $table->string('numero_cni', 50)->nullable();
            $table->string('telephone', 30)->notNull();
            $table->enum('type_situation', ['residente', 'non_residente'])->notNull();
            $table->enum('disponibilite', ['immediate', 'sous_2_semaines', 'sous_1_mois'])->default('immediate');
            $table->foreignId('quartier_domicile_id')->nullable()->constrained('quartiers')->nullOnDelete();
            $table->foreignId('ville_id')->constrained('villes');
            $table->text('adresse_domicile')->nullable();
            $table->enum('statut', [
                'soumis', 'attente_paiement', 'paiement_recu',
                'contrat_formation_signe', 'formation_suivie',
                'disponible', 'en_mission', 'suspendu', 'archive'
            ])->default('soumis');
            $table->enum('statut_casier_judiciaire', ['non_fourni', 'fourni', 'expire', 'valide'])->default('non_fourni');
            $table->text('notes_internes')->nullable();
            $table->timestamp('forfait_paye_at')->nullable();
            $table->timestamp('formation_validee_at')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

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