<?php
namespace App\Scripts;
require_once __DIR__ . '/../vendor/autoload.php';

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->load();

use App\Config\Database;

$taxRates = [
    ['name' => 'GST 18%', 'rate' => 18.00],
    ['name' => 'GST 12%', 'rate' => 12.00],
    ['name' => 'GST 5%', 'rate' => 5.00],
    ['name' => 'GST 28%', 'rate' => 28.00],
    ['name' => 'ST 15%', 'rate' => 15.00],
    ['name' => 'NIL EXEMPT', 'rate' => 0.00]
];

$db = Database::getInstance();
$tenantId = 2; // Default for demo organization

echo "Seeding tax rates for Tenant ID: $tenantId\n";

foreach ($taxRates as $t) {
    try {
        $stmt = $db->prepare("INSERT INTO tax_rates (tenant_id, name, rate, is_active) VALUES (?, ?, ?, 1)");
        $stmt->execute([$tenantId, $t['name'], $t['rate']]);
        echo "Inserted: {$t['name']} ({$t['rate']}%)\n";
    } catch (\PDOException $e) {
        if ($e->getCode() == 23000 || str_contains($e->getMessage(), 'Duplicate entry')) {
            echo "Skipped: {$t['name']} (Already exists)\n";
        } else {
            echo "Error inserting {$t['name']}: " . $e->getMessage() . "\n";
        }
    }
}
echo "Seeding complete.\n";
