<?php
declare(strict_types=1);

/**
 * Creates the group_waitlist table for the Waitlist System.
 * Note: This table may already exist from Phase_63_012. This migration uses IF NOT EXISTS.
 */
return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `group_waitlist` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `group_id` BIGINT UNSIGNED NOT NULL,
            `player_id` BIGINT UNSIGNED NOT NULL,
            `priority` INT UNSIGNED NOT NULL DEFAULT 0,
            `status` ENUM('waiting','offered','accepted','expired') NOT NULL DEFAULT 'waiting',
            `requested_at` DATETIME NOT NULL,
            `offered_at` DATETIME NULL,
            `expires_at` DATETIME NULL,
            `notes` TEXT NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_gw_group` (`group_id`),
            INDEX `idx_gw_player` (`player_id`),
            INDEX `idx_gw_status` (`status`),
            INDEX `idx_gw_priority` (`group_id`, `priority`),
            UNIQUE KEY `uk_gw_group_player` (`group_id`, `player_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `group_waitlist`
    ",
];
