<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_contracts` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_profile_id`   BIGINT UNSIGNED NOT NULL,
            `contract_number`       VARCHAR(30) NOT NULL,
            `contract_type`         VARCHAR(20) NOT NULL COMMENT 'definite, indefinite',
            `start_date`            DATE NOT NULL,
            `end_date`              DATE NULL,
            `probation_months`      INT UNSIGNED NOT NULL DEFAULT 3,
            `basic_salary`          DECIMAL(15,2) NOT NULL,
            `total_package`         DECIMAL(15,2) NOT NULL,
            `working_hours_per_day` DECIMAL(3,1) NOT NULL DEFAULT 8.0,
            `working_days_per_week` INT UNSIGNED NOT NULL DEFAULT 6,
            `notice_period_months`  INT UNSIGNED NOT NULL DEFAULT 2,
            `terms_json`            JSON NULL,
            `status`                VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, active, expired, terminated, renewed',
            `renewal_of_contract_id` BIGINT UNSIGNED NULL,
            `workflow_instance_id`  BIGINT UNSIGNED NULL,
            `signed_date`           DATE NULL,
            `signed_by_employee`    TINYINT(1) NOT NULL DEFAULT 0,
            `signed_by_employer`    TINYINT(1) NOT NULL DEFAULT 0,
            `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_contracts_number` (`contract_number`),
            INDEX `idx_hr_contracts_employee` (`employee_profile_id`),
            INDEX `idx_hr_contracts_status` (`status`),
            INDEX `idx_hr_contracts_dates` (`start_date`, `end_date`),
            INDEX `idx_hr_contracts_workflow` (`workflow_instance_id`),
            INDEX `idx_hr_contracts_archived` (`is_archived`),
            CONSTRAINT `fk_hr_contracts_employee` FOREIGN KEY (`employee_profile_id`) REFERENCES `hr_employee_profiles`(`id`),
            CONSTRAINT `fk_hr_contracts_renewal` FOREIGN KEY (`renewal_of_contract_id`) REFERENCES `hr_contracts`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_hr_contracts_workflow` FOREIGN KEY (`workflow_instance_id`) REFERENCES `workflow_instances`(`id`) ON DELETE SET NULL,
            CONSTRAINT `chk_hr_contracts_type` CHECK (`contract_type` IN ('definite', 'indefinite')),
            CONSTRAINT `chk_hr_contracts_status` CHECK (`status` IN ('draft', 'active', 'expired', 'terminated', 'renewed')),
            CONSTRAINT `chk_hr_contracts_salary` CHECK (`basic_salary` >= 0),
            CONSTRAINT `chk_hr_contracts_package` CHECK (`total_package` >= 0)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_contracts`",
];
