<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_disciplinary_actions` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_profile_id`   BIGINT UNSIGNED NOT NULL,
            `action_number`         VARCHAR(30) NOT NULL,
            `incident_date`         DATE NOT NULL,
            `incident_description`  TEXT NOT NULL,
            `investigation_notes`   TEXT NULL,
            `investigation_by`      BIGINT UNSIGNED NULL,
            `investigation_date`    DATE NULL,
            `penalty_type`          VARCHAR(30) NOT NULL COMMENT 'warning, wage_deduction, raise_postponement, suspension, demotion, termination',
            `penalty_details_json`  JSON NULL,
            `wage_deduction_days`   INT UNSIGNED NULL,
            `wage_deduction_amount` DECIMAL(15,2) NULL,
            `suspension_days`       INT UNSIGNED NULL,
            `effective_date`        DATE NULL,
            `status`                VARCHAR(30) NOT NULL DEFAULT 'investigation' COMMENT 'investigation, pending_decision, decided, appealed, appeal_reviewed, enforced, cancelled',
            `decided_by`            BIGINT UNSIGNED NULL,
            `decided_at`            TIMESTAMP NULL DEFAULT NULL,
            `appeal_deadline`       DATE NULL,
            `appeal_text`           TEXT NULL,
            `appeal_date`           DATE NULL,
            `appeal_result`         VARCHAR(20) NULL COMMENT 'upheld, modified, cancelled',
            `appeal_reviewed_by`    BIGINT UNSIGNED NULL,
            `appeal_reviewed_at`    TIMESTAMP NULL DEFAULT NULL,
            `workflow_instance_id`  BIGINT UNSIGNED 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,
            UNIQUE KEY `uq_hr_disciplinary_number` (`action_number`),
            INDEX `idx_hr_disc_employee` (`employee_profile_id`),
            INDEX `idx_hr_disc_status` (`status`),
            INDEX `idx_hr_disc_type` (`penalty_type`),
            INDEX `idx_hr_disc_date` (`incident_date`),
            INDEX `idx_hr_disc_archived` (`is_archived`),
            CONSTRAINT `fk_hr_disc_employee` FOREIGN KEY (`employee_profile_id`) REFERENCES `hr_employee_profiles`(`id`),
            CONSTRAINT `chk_hr_disc_penalty` CHECK (`penalty_type` IN ('warning', 'wage_deduction', 'raise_postponement', 'suspension', 'demotion', 'termination')),
            CONSTRAINT `chk_hr_disc_status` CHECK (`status` IN ('investigation', 'pending_decision', 'decided', 'appealed', 'appeal_reviewed', 'enforced', 'cancelled')),
            CONSTRAINT `chk_hr_disc_deduction_days` CHECK (`wage_deduction_days` IS NULL OR `wage_deduction_days` <= 5),
            CONSTRAINT `chk_hr_disc_suspension_days` CHECK (`suspension_days` IS NULL OR `suspension_days` <= 6)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_disciplinary_actions`",
];
