<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // For SQLite, we need to recreate the table with the new enum values
        // First, let's drop the check constraint by recreating the column
        
        // SQLite doesn't support ALTER COLUMN, so we need a workaround
        // Create a temporary column, copy data, drop old, rename new
        
        Schema::table('quotes', function (Blueprint $table) {
            $table->string('status_new')->default('pending')->after('status');
        });
        
        // Copy existing status values
        DB::table('quotes')->update(['status_new' => DB::raw('status')]);
        
        // Drop old column and rename new
        Schema::table('quotes', function (Blueprint $table) {
            $table->dropColumn('status');
        });
        
        Schema::table('quotes', function (Blueprint $table) {
            $table->renameColumn('status_new', 'status');
        });
    }

    public function down(): void
    {
        // Reverse is not straightforward, just leave as string
    }
};
