<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\TaxRule;
use App\Models\DepreciationRule;
use App\Models\ImportChargeSetting;

class TaxRuleSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Bangladesh NBR Customs Duty Brackets
        $taxRules = [
            [
                'name' => 'Micro & Small Cars (Up to 1000cc)',
                'cc_min' => 0,
                'cc_max' => 1000,
                'fuel_type' => 'Any',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 0.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Compact city cars like Suzuki Hustler, Spacia, Alto.',
            ],
            [
                'name' => '1001-1500cc Hybrid Vehicles',
                'cc_min' => 1001,
                'cc_max' => 1500,
                'fuel_type' => 'Hybrid',
                'is_hybrid' => true,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 20.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Axio Hybrid, Fielder Hybrid, Honda Grace, Vezel 1.5 e:HEV.',
            ],
            [
                'name' => '1001-1500cc Non-Hybrid Vehicles',
                'cc_min' => 1001,
                'cc_max' => 1500,
                'fuel_type' => 'Petrol',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 20.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Premio 1.5, Allion 1.5, Probox, Succeed.',
            ],
            [
                'name' => '1501-1600cc Hybrid Vehicles',
                'cc_min' => 1501,
                'cc_max' => 1600,
                'fuel_type' => 'Hybrid',
                'is_hybrid' => true,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 30.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Mid-range hybrid crossovers and sedans.',
            ],
            [
                'name' => '1501-1600cc Non-Hybrid Vehicles',
                'cc_min' => 1501,
                'cc_max' => 1600,
                'fuel_type' => 'Petrol',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 45.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Standard 1.6L naturally aspirated vehicles.',
            ],
            [
                'name' => '1601-1800cc Hybrid (Corolla Cross Hybrid)',
                'cc_min' => 1601,
                'cc_max' => 1800,
                'fuel_type' => 'Hybrid',
                'is_hybrid' => true,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 45.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Corolla Cross 1.8 Hybrid, Prius 1.8, C-HR Hybrid.',
            ],
            [
                'name' => '1601-1800cc Non-Hybrid Vehicles',
                'cc_min' => 1601,
                'cc_max' => 1800,
                'fuel_type' => 'Petrol',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 60.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Premio 1.8, Allion 1.8, Honda Civic 1.8.',
            ],
            [
                'name' => '1801-2000cc Hybrid (Harrier & Noah/Voxy Hybrid)',
                'cc_min' => 1801,
                'cc_max' => 2000,
                'fuel_type' => 'Hybrid',
                'is_hybrid' => true,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 60.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Noah/Voxy 90 series Hybrid, Harrier 2.0, RAV4 Hybrid.',
            ],
            [
                'name' => '1801-2000cc Non-Hybrid (Harrier 2.0 Petrol, CX-5)',
                'cc_min' => 1801,
                'cc_max' => 2000,
                'fuel_type' => 'Petrol',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 100.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Harrier 2.0 Petrol, Mazda CX-5 2.0L.',
            ],
            [
                'name' => '2001-2750cc SUVs (Prado TX-L, Harrier 2.5 Hybrid)',
                'cc_min' => 2001,
                'cc_max' => 2750,
                'fuel_type' => 'Any',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 200.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Land Cruiser Prado 2.7L, Fortuner 2.7L.',
            ],
            [
                'name' => '2751-3000cc Luxury Vehicles',
                'cc_min' => 2751,
                'cc_max' => 3000,
                'fuel_type' => 'Any',
                'is_hybrid' => false,
                'customs_duty_rate' => 25.00,
                'regulatory_duty_rate' => 3.00,
                'supplementary_duty_rate' => 350.00,
                'vat_rate' => 15.00,
                'advance_income_tax_rate' => 5.00,
                'advance_tax_rate' => 5.00,
                'description' => 'Toyota Crown 3.0, Lexus RX300.',
            ],
        ];

        foreach ($taxRules as $rule) {
            TaxRule::updateOrCreate(['name' => $rule['name']], $rule);
        }

        // 2. NBR Vehicle Age Depreciation Table
        $depreciations = [
            ['age_years' => 1, 'depreciation_percentage' => 10.00, 'description' => '1 year old vehicle depreciation deduction'],
            ['age_years' => 2, 'depreciation_percentage' => 20.00, 'description' => '2 years old vehicle depreciation deduction'],
            ['age_years' => 3, 'depreciation_percentage' => 30.00, 'description' => '3 years old vehicle depreciation deduction'],
            ['age_years' => 4, 'depreciation_percentage' => 40.00, 'description' => '4-5 years old maximum allowable depreciation deduction in Bangladesh'],
        ];

        foreach ($depreciations as $item) {
            DepreciationRule::updateOrCreate(['age_years' => $item['age_years']], $item);
        }

        // 3. Calculator Standard Fees & Exchange Rates
        $charges = [
            ['charge_key' => 'jpy_to_bdt_rate', 'name' => 'JPY to BDT Exchange Rate', 'currency' => 'BDT', 'amount' => 0.8200, 'category' => 'currency', 'notes' => 'Current commercial exchange rate for Japan import remittances'],
            ['charge_key' => 'auction_fee_jpy', 'name' => 'Japan Auction House Fee', 'currency' => 'JPY', 'amount' => 25000.00, 'category' => 'logistics', 'notes' => 'Standard auction hall gate and handling fee in Japan'],
            ['charge_key' => 'inland_transport_jpy', 'name' => 'Japan Inland Transport', 'currency' => 'JPY', 'amount' => 35000.00, 'category' => 'logistics', 'notes' => 'Carrier transport from auction yard to Yokohama/Kobe export port'],
            ['charge_key' => 'shipping_jpy', 'name' => 'Ocean Freight RORO (Japan to Chittagong)', 'currency' => 'JPY', 'amount' => 180000.00, 'category' => 'logistics', 'notes' => 'Direct car carrier liner shipping to Chittagong Port'],
            ['charge_key' => 'marine_insurance_bdt', 'name' => 'Marine Transit Insurance', 'currency' => 'BDT', 'amount' => 25000.00, 'category' => 'logistics', 'notes' => 'Comprehensive marine transit insurance coverage'],
            ['charge_key' => 'port_cf_bdt', 'name' => 'Chittagong Port & C&F Clearing', 'currency' => 'BDT', 'amount' => 55000.00, 'category' => 'customs', 'notes' => 'Port yard dues, crane charges and authorized C&F agent handling'],
            ['charge_key' => 'brta_registration_bdt', 'name' => 'BRTA Registration & Digital Plate', 'currency' => 'BDT', 'amount' => 135000.00, 'category' => 'registration', 'notes' => 'Registration fees, retro-reflective plates, RFID tag, and 1-year tax token/fitness'],
            ['charge_key' => 'service_charge_bdt', 'name' => 'MotoSolution Concierge Sourcing Fee', 'currency' => 'BDT', 'amount' => 50000.00, 'category' => 'company', 'notes' => 'End-to-end auction inspection, bidding, documentation, and handover support'],
        ];

        foreach ($charges as $charge) {
            ImportChargeSetting::updateOrCreate(['charge_key' => $charge['charge_key']], $charge);
        }
    }
}
