<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('tax_rates', function (Blueprint $table) {
            if (Schema::hasColumn('tax_rates', 'state')) {
                $table->renameColumn('state', 'state_code');
            }
            if (!Schema::hasColumn('tax_rates', 'state_name')) {
                $table->string('state_name')->nullable()->after('state_code');
            }
            if (Schema::hasColumn('tax_rates', 'is_active')) {
                $table->renameColumn('is_active', 'active');
            }
        });
    }

    public function down(): void
    {
        Schema::table('tax_rates', function (Blueprint $table) {
            if (Schema::hasColumn('tax_rates', 'state_code')) {
                $table->renameColumn('state_code', 'state');
            }
            if (Schema::hasColumn('tax_rates', 'state_name')) {
                $table->dropColumn('state_name');
            }
            if (Schema::hasColumn('tax_rates', 'active')) {
                $table->renameColumn('active', 'is_active');
            }
        });
    }
};