<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_leave_requests` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_profile_id`   BIGINT UNSIGNED NOT NULL,
            `leave_type_id`         BIGINT UNSIGNED NOT NULL,
            `start_date`            DATE NOT NULL,
            `end_date`              DATE NOT NULL,
            `total_days`            DECIMAL(5,1) NOT NULL,
            `half_day`              TINYINT(1) NOT NULL DEFAULT 0,
            `half_day_type`         VARCHAR(20) NULL COMMENT 'first_half, second_half',
            `reason`                TEXT NULL,
            `status`                VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'draft, pending, approved, rejected, cancelled',
            `workflow_instance_id`  BIGINT UNSIGNED NULL,
            `approved_by`           BIGINT UNSIGNED NULL,
            `approved_at`           TIMESTAMP NULL DEFAULT NULL,
            `rejection_reason`      TEXT NULL,
            `return_date`           DATE NULL,
            `document_path`         VARCHAR(500) 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_leave_req_employee` (`employee_profile_id`),
            INDEX `idx_hr_leave_req_type` (`leave_type_id`),
            INDEX `idx_hr_leave_req_dates` (`start_date`, `end_date`),
            INDEX `idx_hr_leave_req_status` (`status`),
            INDEX `idx_hr_leave_req_workflow` (`workflow_instance_id`),
            INDEX `idx_hr_leave_req_archived` (`is_archived`),
            CONSTRAINT `fk_hr_leave_req_employee` FOREIGN KEY (`employee_profile_id`) REFERENCES `hr_employee_profiles`(`id`),
            CONSTRAINT `fk_hr_leave_req_type` FOREIGN KEY (`leave_type_id`) REFERENCES `hr_leave_types`(`id`),
            CONSTRAINT `fk_hr_leave_req_approver` FOREIGN KEY (`approved_by`) REFERENCES `employees`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_hr_leave_req_workflow` FOREIGN KEY (`workflow_instance_id`) REFERENCES `workflow_instances`(`id`) ON DELETE SET NULL,
            CONSTRAINT `chk_hr_leave_req_status` CHECK (`status` IN ('draft', 'pending', 'approved', 'rejected', 'cancelled'))
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_leave_requests`",
];
