<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('core_tax_configurations', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('code')->unique();
            $table->decimal('rate', 10, 4); // Tax rate (percentage or fixed amount)
            $table->enum('type', ['percentage', 'fixed'])->default('percentage'); // Tax calculation type
            $table->string('tax_authority')->nullable(); // e.g., "Federal", "State", "GST", "VAT"
            $table->text('description')->nullable();
            $table->boolean('is_default')->default(false); // Default tax rate flag
            $table->boolean('is_active')->default(true);
            $table->foreignId('created_by_id')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by_id')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->softDeletes();

            $table->index('is_active');
            $table->index(['is_active', 'is_default']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('core_tax_configurations');
    }
};
