<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_group_schedule` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `group_id` BIGINT UNSIGNED NOT NULL,
            `facility_unit_id` BIGINT UNSIGNED NOT NULL,
            `day_of_week` TINYINT UNSIGNED NOT NULL COMMENT '0=Sunday, 6=Saturday',
            `start_time` TIME NOT NULL,
            `end_time` TIME NOT NULL,
            `is_active` TINYINT(1) NOT NULL DEFAULT 1,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_sa_gs_group` (`group_id`),
            INDEX `idx_sa_gs_unit` (`facility_unit_id`),
            INDEX `idx_sa_gs_day` (`day_of_week`, `start_time`),
            UNIQUE KEY `uq_sa_gs_slot` (`group_id`, `facility_unit_id`, `day_of_week`, `start_time`),
            CONSTRAINT `fk_sa_gs_group` FOREIGN KEY (`group_id`) REFERENCES `sa_groups`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_sa_gs_unit` FOREIGN KEY (`facility_unit_id`) REFERENCES `sa_facility_units`(`id`) ON DELETE RESTRICT
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `sa_group_schedule`",
];
