<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_payroll_components_log` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `payroll_run_id`        BIGINT UNSIGNED NOT NULL,
            `component_id`          BIGINT UNSIGNED NULL,
            `component_code`        VARCHAR(30) NOT NULL,
            `name_ar`               VARCHAR(200) NOT NULL,
            `type`                  VARCHAR(20) NOT NULL COMMENT 'earning, deduction',
            `amount`                DECIMAL(15,2) NOT NULL,
            `is_taxable`            TINYINT(1) NOT NULL DEFAULT 1,
            `is_insurable`          TINYINT(1) NOT NULL DEFAULT 1,
            `sort_order`            INT UNSIGNED NOT NULL DEFAULT 0,
            `created_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_hr_payroll_comp_run` (`payroll_run_id`),
            INDEX `idx_hr_payroll_comp_code` (`component_code`),
            CONSTRAINT `fk_hr_payroll_comp_run` FOREIGN KEY (`payroll_run_id`) REFERENCES `hr_payroll_runs`(`id`) ON DELETE CASCADE,
            CONSTRAINT `chk_hr_payroll_comp_type` CHECK (`type` IN ('earning', 'deduction'))
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_payroll_components_log`",
];
