<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_end_of_service` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_id`           BIGINT UNSIGNED NOT NULL,
            `termination_type`      VARCHAR(30) NOT NULL COMMENT 'resignation, termination, end_of_contract, retirement, death, disability, mutual_agreement',
            `request_date`          DATE NOT NULL,
            `effective_date`        DATE NOT NULL,
            `last_working_day`      DATE NULL,
            `notice_period_start`   DATE NULL,
            `notice_period_end`     DATE NULL,
            `notice_period_served`  TINYINT(1) NOT NULL DEFAULT 0,
            `notice_period_compensation` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `years_of_service`      DECIMAL(5,2) NOT NULL,
            `last_basic_salary`     DECIMAL(15,2) NOT NULL,
            `last_total_salary`     DECIMAL(15,2) NOT NULL,
            `severance_first_5y`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `severance_after_5y`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_severance`       DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `remaining_leave_days`  DECIMAL(5,1) NOT NULL DEFAULT 0.0,
            `leave_compensation`    DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_entitlement`     DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `deductions_json`       JSON NULL,
            `total_deductions`      DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `net_settlement`        DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `status`                VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, calculated, pending_approval, approved, paid, cancelled',
            `workflow_instance_id`  BIGINT UNSIGNED NULL,
            `approved_by`           BIGINT UNSIGNED NULL,
            `approved_at`           TIMESTAMP NULL DEFAULT NULL,
            `paid_date`             DATE NULL,
            `calculation_json`      JSON NOT 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,
            INDEX `idx_hr_eos_employee` (`employee_id`),
            INDEX `idx_hr_eos_status` (`status`),
            INDEX `idx_hr_eos_type` (`termination_type`),
            INDEX `idx_hr_eos_archived` (`is_archived`),
            CONSTRAINT `fk_hr_eos_employee` FOREIGN KEY (`employee_id`) REFERENCES `employees`(`id`),
            CONSTRAINT `chk_hr_eos_type` CHECK (`termination_type` IN ('resignation', 'termination', 'end_of_contract', 'retirement', 'death', 'disability', 'mutual_agreement')),
            CONSTRAINT `chk_hr_eos_status` CHECK (`status` IN ('draft', 'calculated', 'pending_approval', 'approved', 'paid', 'cancelled'))
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_end_of_service`",
];
