<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_waitlist` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `player_id` BIGINT UNSIGNED NOT NULL,
            `group_id` BIGINT UNSIGNED NOT NULL,
            `position` INT UNSIGNED NOT NULL DEFAULT 0,
            `status` VARCHAR(20) NOT NULL DEFAULT 'waiting' COMMENT 'waiting, offered, accepted, expired, cancelled',
            `offered_at` TIMESTAMP NULL,
            `expires_at` TIMESTAMP NULL,
            `notes` TEXT 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,
            INDEX `idx_sa_wl_player` (`player_id`),
            INDEX `idx_sa_wl_group` (`group_id`),
            INDEX `idx_sa_wl_status` (`status`, `position`),
            CONSTRAINT `fk_sa_wl_player` FOREIGN KEY (`player_id`) REFERENCES `sa_players`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_sa_wl_group` FOREIGN KEY (`group_id`) REFERENCES `sa_groups`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `sa_waitlist`",
];
