<?php
declare(strict_types=1);

return [
    'up' => "CREATE TABLE IF NOT EXISTS `training_groups` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `code` VARCHAR(50) NOT NULL,
    `name_ar` VARCHAR(255) NOT NULL,
    `name_en` VARCHAR(255) NULL,
    `academy_id` BIGINT UNSIGNED NOT NULL,
    `level_id` BIGINT UNSIGNED NOT NULL,
    `coach_id` BIGINT UNSIGNED NULL,
    `facility_id` BIGINT UNSIGNED NULL,
    `group_type` VARCHAR(20) NOT NULL DEFAULT 'group' COMMENT 'private, small_group, group, team',
    `min_capacity` INT UNSIGNED NOT NULL DEFAULT 1,
    `max_capacity` INT UNSIGNED NOT NULL DEFAULT 20,
    `current_count` INT UNSIGNED NOT NULL DEFAULT 0,
    `age_from` INT UNSIGNED NULL,
    `age_to` INT UNSIGNED NULL,
    `gender_restriction` VARCHAR(10) NULL COMMENT 'male, female, NULL=mixed',
    `day_of_week` TINYINT UNSIGNED NULL,
    `start_time` TIME NULL,
    `end_time` TIME NULL,
    `pricing_tier` VARCHAR(20) NOT NULL DEFAULT 'standard' COMMENT 'premium, standard, economy',
    `is_full` TINYINT(1) NOT NULL DEFAULT 0,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `is_archived` TINYINT(1) NOT NULL DEFAULT 0,
    `archived_at` TIMESTAMP 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_tg_code` (`code`),
    INDEX `idx_tg_academy_level` (`academy_id`, `level_id`),
    INDEX `idx_tg_coach` (`coach_id`),
    INDEX `idx_tg_capacity` (`is_full`, `is_active`),
    CONSTRAINT `fk_tg_academy` FOREIGN KEY (`academy_id`) REFERENCES `academies`(`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_tg_level` FOREIGN KEY (`level_id`) REFERENCES `academy_levels`(`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_tg_coach` FOREIGN KEY (`coach_id`) REFERENCES `coaches`(`id`) ON DELETE SET NULL,
    CONSTRAINT `fk_tg_facility` FOREIGN KEY (`facility_id`) REFERENCES `facilities`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "DROP TABLE IF EXISTS `training_groups`",
];
