<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_games` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `name_ar` VARCHAR(200) NOT NULL,
            `name_en` VARCHAR(200) NULL,
            `description` TEXT NULL,
            `game_type` VARCHAR(30) NOT NULL DEFAULT 'free_play' COMMENT 'free_play, tournament, session',
            `facility_id` BIGINT UNSIGNED NULL,
            `max_players` INT UNSIGNED NOT NULL DEFAULT 20,
            `duration_minutes` INT UNSIGNED NOT NULL DEFAULT 60,
            `fee_member` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `fee_nonmember` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `is_active` TINYINT(1) NOT NULL DEFAULT 1,
            `branch_id` BIGINT UNSIGNED NULL,
            `created_by` BIGINT UNSIGNED NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_sa_games_active` (`is_active`),
            INDEX `idx_sa_games_type` (`game_type`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE `sa_game_sessions` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `game_id` BIGINT UNSIGNED NOT NULL,
            `session_date` DATE NOT NULL,
            `start_time` TIME NOT NULL,
            `end_time` TIME NOT NULL,
            `facility_unit_id` BIGINT UNSIGNED NULL,
            `max_players` INT UNSIGNED NOT NULL DEFAULT 20,
            `current_players` INT UNSIGNED NOT NULL DEFAULT 0,
            `status` VARCHAR(20) NOT NULL DEFAULT 'open' COMMENT 'open, full, in_progress, completed, cancelled',
            `notes` TEXT NULL,
            `created_by` BIGINT UNSIGNED NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_sa_gs_game` (`game_id`),
            INDEX `idx_sa_gs_date` (`session_date`),
            INDEX `idx_sa_gs_status` (`status`),
            CONSTRAINT `fk_sa_gs_game` FOREIGN KEY (`game_id`) REFERENCES `sa_games`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE `sa_game_tickets` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `session_id` BIGINT UNSIGNED NOT NULL,
            `ticket_number` VARCHAR(50) NOT NULL,
            `player_id` BIGINT UNSIGNED NULL,
            `player_name` VARCHAR(200) NULL COMMENT 'For walk-in guests',
            `player_type` VARCHAR(20) NOT NULL DEFAULT 'guest' COMMENT 'member, non_member, guest',
            `fee_charged` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `payment_status` VARCHAR(20) NOT NULL DEFAULT 'unpaid' COMMENT 'unpaid, paid, refunded',
            `payment_id` BIGINT UNSIGNED NULL,
            `checked_in` TINYINT(1) NOT NULL DEFAULT 0,
            `checked_in_at` TIMESTAMP NULL,
            `status` VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT 'active, cancelled, no_show',
            `created_by` BIGINT UNSIGNED NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            UNIQUE KEY `uq_sa_gt_number` (`ticket_number`),
            INDEX `idx_sa_gt_session` (`session_id`),
            INDEX `idx_sa_gt_player` (`player_id`),
            INDEX `idx_sa_gt_status` (`status`),
            CONSTRAINT `fk_sa_gt_session` FOREIGN KEY (`session_id`) REFERENCES `sa_game_sessions`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
    ",
    'down' => "
        DROP TABLE IF EXISTS `sa_game_tickets`;
        DROP TABLE IF EXISTS `sa_game_sessions`;
        DROP TABLE IF EXISTS `sa_games`;
    ",
];
