<?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
    {
        $map = [
            'petrol' => 'e10',
            'unleaded' => 'e10',
            'premium_unleaded' => 'e5',
            'diesel' => 'b7_standard',
            'premium_diesel' => 'b7_premium',
        ];

        foreach ($map as $from => $to) {
            DB::table('users')->where('preferred_fuel_type', $from)->update(['preferred_fuel_type' => $to]);
        }

        Schema::table('users', function (Blueprint $table) {
            $table->string('preferred_fuel_type', 20)->default('e10')->change();
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('preferred_fuel_type', 20)->default('petrol')->change();
        });

        DB::table('users')->where('preferred_fuel_type', 'e10')->update(['preferred_fuel_type' => 'petrol']);
        DB::table('users')->where('preferred_fuel_type', 'b7_standard')->update(['preferred_fuel_type' => 'diesel']);
    }
};
