<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('territoire', function (Blueprint $table) {
            $table->string('terr_badge_fr')->nullable()->after('terr_hub');
            $table->string('terr_badge_en')->nullable()->after('terr_badge_fr');
        });

        DB::table('territoire')->update([
            'terr_badge_fr' => DB::raw('terr_badge'),
        ]);

        $translations = [
            'Hub' => 'Hub',
            'UE' => 'EU',
            'Potentiel' => 'Potential',
            'Émergent' => 'Emerging',
            'France' => 'France',
        ];

        foreach ($translations as $fr => $en) {
            DB::table('territoire')->where('terr_badge', $fr)->update([
                'terr_badge_en' => $en,
            ]);
        }

        Schema::table('territoire', function (Blueprint $table) {
            $table->dropColumn('terr_badge');
        });
    }

    public function down(): void
    {
        Schema::table('territoire', function (Blueprint $table) {
            $table->string('terr_badge')->nullable()->after('terr_hub');
        });

        DB::table('territoire')->update([
            'terr_badge' => DB::raw('terr_badge_fr'),
        ]);

        Schema::table('territoire', function (Blueprint $table) {
            $table->dropColumn(['terr_badge_fr', 'terr_badge_en']);
        });
    }
};
