<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `fiscal_years` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `name_ar`         VARCHAR(100)    NOT NULL COMMENT 'e.g. السنة المالية 2025/2026',
            `name_en`         VARCHAR(100)    NOT NULL COMMENT 'e.g. FY 2025/2026',
            `start_date`      DATE            NOT NULL,
            `end_date`        DATE            NOT NULL,
            `status`          ENUM('open','closing','closed') NOT NULL DEFAULT 'open',
            `is_current`      TINYINT(1)      NOT NULL DEFAULT 0,
            `closed_at`       DATETIME        NULL,
            `closed_by`       BIGINT UNSIGNED NULL,
            `notes`           TEXT            NULL,
            `is_archived`     TINYINT(1)      NOT NULL DEFAULT 0,
            `archived_at`     DATETIME        NULL,
            `archived_by`     BIGINT UNSIGNED NULL,
            `created_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`      BIGINT UNSIGNED NULL,
            `updated_by`      BIGINT UNSIGNED NULL,

            INDEX `idx_fiscal_years_status`     (`status`),
            INDEX `idx_fiscal_years_current`    (`is_current`),
            INDEX `idx_fiscal_years_dates`      (`start_date`, `end_date`),
            CONSTRAINT `fk_fiscal_years_closed_by`   FOREIGN KEY (`closed_by`)   REFERENCES `employees`(`id`),
            CONSTRAINT `fk_fiscal_years_created_by`  FOREIGN KEY (`created_by`)  REFERENCES `employees`(`id`),
            CONSTRAINT `fk_fiscal_years_updated_by`  FOREIGN KEY (`updated_by`)  REFERENCES `employees`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `fiscal_years`",
];
