<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_performance_reviews` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `cycle_id`              BIGINT UNSIGNED NOT NULL,
            `employee_id`           BIGINT UNSIGNED NOT NULL,
            `reviewer_id`           BIGINT UNSIGNED NOT NULL,
            `review_date`           DATE NULL,
            `overall_rating`        DECIMAL(3,1) NULL,
            `rating_label`          VARCHAR(20) NULL COMMENT 'excellent, very_good, good, acceptable, poor',
            `scores_json`           JSON NULL,
            `strengths`             TEXT NULL,
            `improvements`          TEXT NULL,
            `goals_json`            JSON NULL,
            `employee_comment`      TEXT NULL,
            `status`                VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, in_progress, submitted, acknowledged',
            `acknowledged_by_employee` TINYINT(1) NOT NULL DEFAULT 0,
            `acknowledged_at`       TIMESTAMP NULL DEFAULT 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,
            UNIQUE KEY `uq_hr_perf_review` (`cycle_id`, `employee_id`),
            INDEX `idx_hr_perf_review_employee` (`employee_id`),
            INDEX `idx_hr_perf_review_reviewer` (`reviewer_id`),
            INDEX `idx_hr_perf_review_status` (`status`),
            CONSTRAINT `fk_hr_perf_review_cycle` FOREIGN KEY (`cycle_id`) REFERENCES `hr_performance_cycles`(`id`),
            CONSTRAINT `fk_hr_perf_review_employee` FOREIGN KEY (`employee_id`) REFERENCES `employees`(`id`),
            CONSTRAINT `fk_hr_perf_review_reviewer` FOREIGN KEY (`reviewer_id`) REFERENCES `employees`(`id`),
            CONSTRAINT `chk_hr_perf_review_status` CHECK (`status` IN ('pending', 'in_progress', 'submitted', 'acknowledged')),
            CONSTRAINT `chk_hr_perf_review_rating` CHECK (`overall_rating` IS NULL OR (`overall_rating` >= 1.0 AND `overall_rating` <= 5.0))
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_performance_reviews`",
];
