<?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('customers', function (Blueprint $table) {
            $table->string('code', 30)->nullable()->unique()->after('id');
            $table->string('tax_number', 50)->nullable()->after('address');
            $table->boolean('is_active')->default(true)->after('tax_number');
            $table->foreignId('created_by')->nullable()->after('is_active')->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->after('created_by')->constrained('users')->nullOnDelete();
            $table->index('whatsapp');
        });
    }

    public function down(): void
    {
        Schema::table('customers', function (Blueprint $table) {
            $table->dropConstrainedForeignId('updated_by');
            $table->dropConstrainedForeignId('created_by');
            $table->dropIndex(['whatsapp']);
            $table->dropUnique(['code']);
            $table->dropColumn(['code', 'tax_number', 'is_active']);
        });
    }
};