<?php
declare(strict_types=1);

return [
    'up' => "
ALTER TABLE sa_pool_zone_bookings ADD COLUMN access_mode ENUM('reserved','open_access') NOT NULL DEFAULT 'reserved' AFTER assignment_type;
ALTER TABLE sa_pool_zone_bookings ADD COLUMN access_restriction ENUM('all','members_only') NULL AFTER access_mode;
ALTER TABLE sa_pool_zone_bookings ADD COLUMN ticket_price_member DECIMAL(10,2) NULL AFTER access_restriction;
ALTER TABLE sa_pool_zone_bookings ADD COLUMN ticket_price_nonmember DECIMAL(10,2) NULL AFTER ticket_price_member;
ALTER TABLE sa_pool_zone_bookings ADD COLUMN max_occupancy INT UNSIGNED NULL AFTER ticket_price_nonmember;
ALTER TABLE sa_pool_zone_bookings ADD COLUMN current_occupancy INT UNSIGNED NOT NULL DEFAULT 0 AFTER max_occupancy;
CREATE TABLE sa_pool_tickets (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    facility_id INT UNSIGNED NOT NULL,
    zone_booking_id BIGINT UNSIGNED NULL,
    booking_date DATE NOT NULL,
    start_time TIME NOT NULL,
    end_time TIME NOT NULL,
    member_id INT UNSIGNED NULL,
    player_id INT UNSIGNED NULL,
    guest_name VARCHAR(200) NULL,
    guest_national_id VARCHAR(14) NULL,
    is_member TINYINT(1) NOT NULL DEFAULT 0,
    amount_paid DECIMAL(10,2) NOT NULL DEFAULT 0.00,
    payment_status ENUM('unpaid','paid','refunded') NOT NULL DEFAULT 'unpaid',
    payment_request_id INT UNSIGNED NULL,
    entry_time DATETIME NULL,
    exit_time DATETIME NULL,
    status ENUM('issued','active','completed','cancelled') NOT NULL DEFAULT 'issued',
    issued_by INT UNSIGNED NULL,
    branch_id INT UNSIGNED NULL,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL,
    INDEX idx_pt_facility_date (facility_id, booking_date),
    INDEX idx_pt_zone (zone_booking_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
",
    'down' => "
DROP TABLE IF EXISTS sa_pool_tickets;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN current_occupancy;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN max_occupancy;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN ticket_price_nonmember;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN ticket_price_member;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN access_restriction;
ALTER TABLE sa_pool_zone_bookings DROP COLUMN access_mode
",
];
