<?php

namespace Database\Seeders;

use App\Models\Setting;
use App\Models\TaxRule;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Cache;

class TaxRuleSeeder extends Seeder
{
    public function run(): void
    {
        // QA fixtures (PRC-532): deterministik vergi kataloğu — idempotent.
        TaxRule::query()->delete();

        $rules = [
            ['name' => 'KDV',         'rate' => 20.00, 'countries' => ['TR'], 'all_countries' => false],
            ['name' => 'VAT',         'rate' => 20.00, 'countries' => ['GB'], 'all_countries' => false],
            ['name' => 'MwSt',        'rate' => 19.00, 'countries' => ['DE'], 'all_countries' => false],
            ['name' => 'Default Tax', 'rate' => 10.00, 'countries' => null,   'all_countries' => true],
        ];

        foreach ($rules as $rule) {
            TaxRule::create($rule);
        }

        // Vergi exclusive (fiyat üstüne eklenir). TaxCalculationService
        // getSetting('tax_method', 'exclusive') bu satırı okur.
        Setting::updateOrCreate(
            ['key' => 'tax_method'],
            ['value' => 'exclusive', 'group' => 'taxes']
        );
        Cache::forget('setting_tax_method');
    }
}
