<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (!Schema::hasTable('shipments')) {
            return;
        }

        DB::statement("
            ALTER TABLE `shipments`
            MODIFY `status` VARCHAR(100) NOT NULL DEFAULT 'pending'
        ");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (!Schema::hasTable('shipments')) {
            return;
        }

        // Ensure values fit the enum before reverting.
        DB::table('shipments')
            ->whereNotIn('status', ['pending', 'created', 'failed', 'delivered'])
            ->update(['status' => 'created']);

        DB::statement("
            ALTER TABLE `shipments`
            MODIFY `status` ENUM('pending','created','failed','delivered') NOT NULL DEFAULT 'pending'
        ");
    }
};


