<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_tax_records` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_id`           BIGINT UNSIGNED NOT NULL,
            `period_id`             BIGINT UNSIGNED NOT NULL,
            `payroll_run_id`        BIGINT UNSIGNED NULL,
            `month`                 INT UNSIGNED NULL,
            `gross_taxable_monthly` DECIMAL(15,2) NOT NULL,
            `annual_taxable_income` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `personal_exemption`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `insurance_exemption`   DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `net_taxable_income`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `annual_tax`            DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `monthly_tax`           DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `ytd_tax`               DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `ytd_taxable_income`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `calculation_json`      JSON NULL,
            `notes`                 TEXT NULL,
            `created_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`            BIGINT UNSIGNED NULL,
            `updated_by`            BIGINT UNSIGNED NULL,
            `is_archived`           TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`           TIMESTAMP NULL DEFAULT NULL,
            `archived_by`           BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_hr_tax_emp_period` (`employee_id`, `period_id`),
            INDEX `idx_hr_tax_employee` (`employee_id`),
            INDEX `idx_hr_tax_period` (`period_id`),
            CONSTRAINT `fk_hr_tax_employee` FOREIGN KEY (`employee_id`) REFERENCES `employees`(`id`),
            CONSTRAINT `fk_hr_tax_period` FOREIGN KEY (`period_id`) REFERENCES `hr_payroll_periods`(`id`),
            CONSTRAINT `fk_hr_tax_payroll` FOREIGN KEY (`payroll_run_id`) REFERENCES `hr_payroll_runs`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_tax_records`",
];
