<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // Normalize existing values to valid ones
        try {
            DB::table('item_categories')
                ->whereNotIn('status', ['active','inactive'])
                ->orWhereNull('status')
                ->update(['status' => 'active']);
        } catch (\Throwable $e) {
            // ignore
        }

        // Alter enum to only ['active','inactive']
        DB::statement("ALTER TABLE item_categories MODIFY status ENUM('active','inactive') NOT NULL DEFAULT 'active'");
    }

    public function down(): void
    {
        // Revert to the broader set if needed (matches earlier migration in this project)
        DB::statement("ALTER TABLE item_categories MODIFY status ENUM('draft','active','inactive','archived') NOT NULL DEFAULT 'active'");
    }
};


