<?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
    {
        if (! Schema::hasColumn('customers', 'is_active')) {
            Schema::table('customers', function (Blueprint $table) {
                $table->boolean('is_active')->default(true)->index()->after('pin_changed_at');
            });
        }

        if (! Schema::hasColumn('suppliers', 'is_active')) {
            Schema::table('suppliers', function (Blueprint $table) {
                $table->boolean('is_active')->default(true)->index()->after('address');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('customers', 'is_active')) {
            Schema::table('customers', function (Blueprint $table) {
                $table->dropColumn('is_active');
            });
        }

        if (Schema::hasColumn('suppliers', 'is_active')) {
            Schema::table('suppliers', function (Blueprint $table) {
                $table->dropColumn('is_active');
            });
        }
    }
};
