<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_payroll_periods` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `period_code`           VARCHAR(20) NOT NULL,
            `year`                  YEAR NOT NULL,
            `month`                 INT UNSIGNED NOT NULL,
            `start_date`            DATE NOT NULL,
            `end_date`              DATE NOT NULL,
            `status`                VARCHAR(20) NOT NULL DEFAULT 'open' COMMENT 'open, processing, calculated, approved, paid, closed',
            `is_locked`             TINYINT(1) NOT NULL DEFAULT 0,
            `locked_at`             TIMESTAMP NULL DEFAULT NULL,
            `locked_by`             BIGINT UNSIGNED NULL,
            `approved_by`           BIGINT UNSIGNED NULL,
            `approved_at`           TIMESTAMP NULL DEFAULT NULL,
            `paid_date`             DATE NULL,
            `total_gross`           DECIMAL(15,2) NULL,
            `total_deductions`      DECIMAL(15,2) NULL,
            `total_net`             DECIMAL(15,2) NULL,
            `total_employer_cost`   DECIMAL(15,2) 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_payroll_period` (`period_code`),
            UNIQUE KEY `uq_hr_payroll_ym` (`year`, `month`),
            INDEX `idx_hr_payroll_status` (`status`),
            CONSTRAINT `chk_hr_payroll_status` CHECK (`status` IN ('open', 'processing', 'calculated', 'approved', 'paid', 'closed')),
            CONSTRAINT `chk_hr_payroll_month` CHECK (`month` BETWEEN 1 AND 12)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_payroll_periods`",
];
