<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $mapping = [
            'draft' => 'created',
            'waiting_documents' => 'en_cours',
            'documents_received' => 'en_cours',
            'processing' => 'en_cours',
            'additional_documents_requested' => 'en_attente_client',
            'waiting_client_validation' => 'en_attente_client',
            'validated' => 'termine',
            'closed' => 'ferme',
            'cancelled' => 'ferme',
        ];

        foreach ($mapping as $old => $new) {
            DB::table('declarations')
                ->where('status', $old)
                ->update(['status' => $new]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Data migration cannot be reversed — old status distinctions are lost
    }
};
