<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_bookings` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `booking_number` VARCHAR(50) NOT NULL,
            `facility_unit_id` BIGINT UNSIGNED NOT NULL,
            `booking_type` VARCHAR(20) NOT NULL COMMENT 'hourly, training, maintenance, blocked',
            `booking_date` DATE NOT NULL,
            `start_time` TIME NOT NULL,
            `end_time` TIME NOT NULL,
            `group_id` BIGINT UNSIGNED NULL,
            `coach_id` BIGINT UNSIGNED NULL,
            `booker_type` VARCHAR(20) NULL COMMENT 'player, member, guest, academy',
            `booker_id` BIGINT UNSIGNED NULL,
            `booker_name` VARCHAR(300) NULL,
            `participant_count` INT UNSIGNED NOT NULL DEFAULT 1,
            `spots_reserved` INT UNSIGNED NOT NULL DEFAULT 1,
            `total_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
            `payment_status` VARCHAR(20) NOT NULL DEFAULT 'unpaid' COMMENT 'unpaid, paid, partial, refunded',
            `status` VARCHAR(20) NOT NULL DEFAULT 'confirmed' COMMENT 'pending, confirmed, checked_in, completed, cancelled, no_show',
            `is_recurring` TINYINT(1) NOT NULL DEFAULT 0,
            `recurrence_pattern_json` JSON NULL,
            `parent_booking_id` BIGINT UNSIGNED NULL,
            `cancellation_reason` TEXT NULL,
            `cancelled_by` BIGINT UNSIGNED NULL,
            `cancelled_at` TIMESTAMP NULL,
            `notes` TEXT NULL,
            `branch_id` BIGINT UNSIGNED 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,
            `updated_by` BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_sa_bk_number` (`booking_number`),
            INDEX `idx_sa_bk_unit_date` (`facility_unit_id`, `booking_date`, `start_time`),
            INDEX `idx_sa_bk_type` (`booking_type`),
            INDEX `idx_sa_bk_status` (`status`),
            INDEX `idx_sa_bk_group` (`group_id`),
            INDEX `idx_sa_bk_coach` (`coach_id`),
            INDEX `idx_sa_bk_date` (`booking_date`),
            INDEX `idx_sa_bk_parent` (`parent_booking_id`),
            CONSTRAINT `fk_sa_bk_unit` FOREIGN KEY (`facility_unit_id`) REFERENCES `sa_facility_units`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_sa_bk_group` FOREIGN KEY (`group_id`) REFERENCES `sa_groups`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_sa_bk_coach` FOREIGN KEY (`coach_id`) REFERENCES `sa_coaches`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `sa_bookings`",
];
