<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Update any existing 'labor' values to 'labour' first
        DB::statement("UPDATE estimate_line_items SET type = 'labour' WHERE type = 'labor'");

        // Modify the enum to use British spelling
        DB::statement("ALTER TABLE estimate_line_items MODIFY COLUMN type ENUM('labour', 'parts', 'miscellaneous') NOT NULL");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Update any existing 'labour' values back to 'labor'
        DB::statement("UPDATE estimate_line_items SET type = 'labor' WHERE type = 'labour'");

        // Revert the enum to use American spelling
        DB::statement("ALTER TABLE estimate_line_items MODIFY COLUMN type ENUM('labor', 'parts', 'miscellaneous') NOT NULL");
    }
};
