<?php
declare(strict_types=1);

return [
    'up' => "CREATE TABLE IF NOT EXISTS `pool_bookings` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `booking_code` VARCHAR(50) NOT NULL,
    `pool_config_id` BIGINT UNSIGNED NOT NULL,
    `booking_date` DATE NOT NULL,
    `start_time` TIME NOT NULL,
    `end_time` TIME NOT NULL,
    `booking_type` VARCHAR(30) NOT NULL COMMENT 'lap_swimming, lessons, free_swim, academy_session, competition, maintenance',
    `selection_mode` VARCHAR(20) NOT NULL COMMENT 'full_pool, lane, multi_lane',
    `lanes_json` JSON NOT NULL COMMENT 'array of lane numbers booked',
    `booker_type` VARCHAR(20) NOT NULL DEFAULT 'member' COMMENT 'member, non_member, academy, staff',
    `booker_id` BIGINT UNSIGNED NULL,
    `booker_name` VARCHAR(300) NULL,
    `expected_swimmers` INT UNSIGNED NOT NULL DEFAULT 1,
    `actual_swimmers` INT UNSIGNED NULL,
    `unit_rate` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `total_amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
    `payment_status` VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, paid, exempt',
    `payment_id` BIGINT UNSIGNED NULL,
    `status` VARCHAR(20) NOT NULL DEFAULT 'confirmed' COMMENT 'confirmed, checked_in, completed, cancelled, no_show',
    `cancelled_by` BIGINT UNSIGNED NULL,
    `cancelled_at` TIMESTAMP 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,
    `created_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `uq_pb_code` (`booking_code`),
    INDEX `idx_pb_pool_date` (`pool_config_id`, `booking_date`),
    INDEX `idx_pb_date_time` (`booking_date`, `start_time`, `end_time`),
    INDEX `idx_pb_status` (`status`),
    CONSTRAINT `fk_pb_pool` FOREIGN KEY (`pool_config_id`) REFERENCES `pool_configurations`(`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
    'down' => "DROP TABLE IF EXISTS `pool_bookings`",
];
