<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `reservations` (
            `id`                   BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `reservation_number`   VARCHAR(50) NOT NULL,
            `facility_id`          BIGINT UNSIGNED NOT NULL,
            `booker_type`          VARCHAR(20) NOT NULL COMMENT 'member, non_member, player, guest',
            `player_id`            BIGINT UNSIGNED NULL,
            `member_id`            BIGINT UNSIGNED NULL,
            `booker_name`          VARCHAR(300) NULL COMMENT 'For guest bookings',
            `booker_phone`         VARCHAR(30) NULL,
            `reservation_date`     DATE NOT NULL,
            `start_time`           TIME NOT NULL,
            `end_time`             TIME NOT NULL,
            `duration_hours`       DECIMAL(5,2) NOT NULL DEFAULT 1.00,
            `time_tier`            VARCHAR(5) NOT NULL DEFAULT 'AM' COMMENT 'AM, PM',
            `unit_rate`            DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `total_amount`         DECIMAL(15,2) NOT NULL DEFAULT 0.00,
            `payment_id`           BIGINT UNSIGNED NULL,
            `status`               VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, confirmed, checked_in, completed, cancelled, no_show',
            `confirmed_at`         TIMESTAMP NULL DEFAULT NULL,
            `cancelled_at`         TIMESTAMP NULL DEFAULT NULL,
            `cancel_reason`        VARCHAR(500) NULL,
            `notes`                TEXT NULL,
            `created_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `is_archived`          TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`          TIMESTAMP NULL DEFAULT NULL,
            `archived_by`          BIGINT UNSIGNED NULL,
            `created_by`           BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_reservations_number` (`reservation_number`),
            INDEX `idx_reservations_facility` (`facility_id`),
            INDEX `idx_reservations_date` (`reservation_date`),
            INDEX `idx_reservations_status` (`status`),
            INDEX `idx_reservations_player` (`player_id`),
            INDEX `idx_reservations_member` (`member_id`),
            INDEX `idx_reservations_facility_date` (`facility_id`, `reservation_date`, `start_time`, `end_time`),
            CONSTRAINT `fk_reservations_facility` FOREIGN KEY (`facility_id`) REFERENCES `facilities`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_reservations_player` FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_reservations_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_reservations_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `reservations`",
];
