<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('projects', function (Blueprint $table) {
            // First, modify existing data to prevent truncation issues if strict mode is on
            // But we are changing enum to string, so 'actif' is a valid string.
            // We can just change the type first.
            $table->string('status')->change();
        });

        // Update existing values
        DB::table('projects')->where('status', 'actif')->update(['status' => 'encours']);

        // Set default value
        Schema::table('projects', function (Blueprint $table) {
            $table->string('status')->default('encours')->change();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Revert data
        DB::table('projects')->where('status', 'encours')->update(['status' => 'actif']);

        Schema::table('projects', function (Blueprint $table) {
            // Revert to enum
            $table->enum('status', ['actif', 'termine'])->default('actif')->change();
        });
    }
};
