<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('tax_setup', function (Blueprint $table) {
            $table->id();
            $table->boolean('is_enabled')->default(false);
            $table->foreignId('active_tax_id')->nullable()->constrained('taxes')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
        });

        // Seed one row so there is always a single configuration record
        DB::table('tax_setup')->insert([
            'is_enabled' => false,
            'active_tax_id' => null,
            'updated_by' => null,
            'created_at' => now(),
            'updated_at' => now(),
        ]);
    }

    public function down(): void
    {
        Schema::dropIfExists('tax_setup');
    }
};
