<?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::create('tax_rules', function (Blueprint $table) {
            $table->id();
            $table->string('name'); // "1001-1500cc Hybrid", "1501-1600cc Non-Hybrid", etc.
            $table->unsignedInteger('cc_min');
            $table->unsignedInteger('cc_max');
            $table->string('fuel_type')->default('Any'); // Any, Hybrid, Petrol, Diesel
            $table->boolean('is_hybrid')->default(false);

            // Duty percentages based on Bangladesh National Board of Revenue (NBR) Customs structure
            $table->decimal('customs_duty_rate', 6, 2)->default(25.00); // CD % (Assessable value)
            $table->decimal('regulatory_duty_rate', 6, 2)->default(3.00); // RD % (Assessable value)
            $table->decimal('supplementary_duty_rate', 6, 2)->default(20.00); // SD % (AV + CD + RD)
            $table->decimal('vat_rate', 6, 2)->default(15.00); // VAT % (AV + CD + RD + SD)
            $table->decimal('advance_income_tax_rate', 6, 2)->default(5.00); // AIT % (Assessable value)
            $table->decimal('advance_tax_rate', 6, 2)->default(5.00); // AT % (AV + CD + RD + SD)

            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        Schema::create('depreciation_rules', function (Blueprint $table) {
            $table->id();
            $table->unsignedTinyInteger('age_years'); // 1, 2, 3, 4, 5
            $table->decimal('depreciation_percentage', 5, 2); // 0%, 10%, 20%, 30%, 40%
            $table->string('description')->nullable();
            $table->timestamps();
        });

        Schema::create('import_charge_settings', function (Blueprint $table) {
            $table->id();
            $table->string('charge_key')->unique(); // e.g. jpy_rate, auction_fee_jpy, shipping_jpy, port_cf_bdt
            $table->string('name'); // "Exchange Rate (JPY to BDT)", "Japan Inland Freight", etc.
            $table->string('currency', 5)->default('BDT'); // BDT, JPY, USD
            $table->decimal('amount', 14, 4);
            $table->enum('type', ['fixed', 'percentage'])->default('fixed');
            $table->string('category')->default('logistics'); // logistics, customs, registration, company
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('import_charge_settings');
        Schema::dropIfExists('depreciation_rules');
        Schema::dropIfExists('tax_rules');
    }
};
