<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_insurance_records` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_profile_id`   BIGINT UNSIGNED NOT NULL,
            `period_id`             BIGINT UNSIGNED NOT NULL,
            `payroll_run_id`        BIGINT UNSIGNED NULL,
            `basic_insurable_salary`  DECIMAL(15,2) NOT NULL,
            `variable_insurable_salary` DECIMAL(15,2) NOT NULL,
            `employee_basic_share`  DECIMAL(15,2) NOT NULL,
            `employee_variable_share` DECIMAL(15,2) NOT NULL,
            `total_employee_share`  DECIMAL(15,2) NOT NULL,
            `employer_basic_share`  DECIMAL(15,2) NOT NULL,
            `employer_variable_share` DECIMAL(15,2) NOT NULL,
            `total_employer_share`  DECIMAL(15,2) NOT NULL,
            `total_contribution`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `insurance_number`      VARCHAR(20) 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_insurance_emp_period` (`employee_profile_id`, `period_id`),
            INDEX `idx_hr_insurance_employee` (`employee_profile_id`),
            INDEX `idx_hr_insurance_period` (`period_id`),
            INDEX `idx_hr_insurance_payroll` (`payroll_run_id`),
            CONSTRAINT `fk_hr_insurance_period` FOREIGN KEY (`period_id`) REFERENCES `hr_payroll_periods`(`id`),
            CONSTRAINT `fk_hr_insurance_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_insurance_records`",
];
