<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `facility_monthly_plans` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `grid_id` BIGINT UNSIGNED NOT NULL,
            `plan_month` VARCHAR(7) NOT NULL COMMENT 'YYYY-MM',
            `plan_name_ar` VARCHAR(200) NOT NULL,
            `plan_name_en` VARCHAR(200) NULL,
            `status` VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, active, archived',
            `working_days_json` JSON NOT NULL,
            `day_hours_start` TIME NOT NULL DEFAULT '06:00:00',
            `day_hours_end` TIME NOT NULL DEFAULT '14:00:00',
            `night_hours_start` TIME NOT NULL DEFAULT '14:00:00',
            `night_hours_end` TIME NOT NULL DEFAULT '22:00:00',
            `cloned_from_id` BIGINT UNSIGNED NULL,
            `total_sessions` INT UNSIGNED NOT NULL DEFAULT 0,
            `total_coaches` INT UNSIGNED NOT NULL DEFAULT 0,
            `total_trainees` INT UNSIGNED NOT NULL DEFAULT 0,
            `notes` TEXT NULL,
            `activated_at` DATETIME NULL,
            `activated_by` BIGINT UNSIGNED 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,
            UNIQUE KEY `uq_fmp_grid_month` (`grid_id`, `plan_month`),
            INDEX `idx_fmp_status` (`status`),
            CONSTRAINT `fk_fmp_grid` FOREIGN KEY (`grid_id`) REFERENCES `facility_grids`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        ALTER TABLE `facility_zone_schedules`
            ADD COLUMN `plan_id` BIGINT UNSIGNED NULL AFTER `plan_month`,
            ADD INDEX `idx_fzs_plan_id` (`plan_id`)
    ",
    'down' => "
        ALTER TABLE `facility_zone_schedules` DROP INDEX `idx_fzs_plan_id`, DROP COLUMN `plan_id`;
        DROP TABLE IF EXISTS `facility_monthly_plans`
    ",
];
