<?php
declare(strict_types=1);

return [
    'up' => "
        ALTER TABLE `carnets`
            ADD COLUMN `total_invitations` INT UNSIGNED NOT NULL DEFAULT 10 AFTER `carnet_type`,
            ADD COLUMN `used_invitations` INT UNSIGNED NOT NULL DEFAULT 0 AFTER `total_invitations`;

        CREATE TABLE IF NOT EXISTS `carnet_guest_entries` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `carnet_id` BIGINT UNSIGNED NOT NULL,
            `member_id` BIGINT UNSIGNED NOT NULL,
            `guest_name` VARCHAR(200) NOT NULL,
            `guest_phone` VARCHAR(30) NULL,
            `guest_national_id` VARCHAR(20) NULL,
            `guest_count` INT UNSIGNED NOT NULL DEFAULT 1,
            `entry_date` DATE NOT NULL,
            `entry_time` TIME NOT NULL,
            `exit_time` TIME NULL,
            `facility_id` BIGINT UNSIGNED NULL,
            `activity_type` VARCHAR(50) NOT NULL COMMENT 'free_swim, court_booking, recreation, ping_pong, bowling, playstation',
            `reservation_id` BIGINT UNSIGNED NULL,
            `pool_booking_id` BIGINT UNSIGNED NULL,
            `amount_paid` DECIMAL(10,2) NOT NULL DEFAULT 0,
            `payment_id` BIGINT UNSIGNED NULL,
            `status` VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT 'active, checked_out, cancelled',
            `notes` TEXT NULL,
            `recorded_by` BIGINT UNSIGNED NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_cge_carnet` (`carnet_id`),
            INDEX `idx_cge_member` (`member_id`),
            INDEX `idx_cge_date` (`entry_date`),
            INDEX `idx_cge_status` (`status`),
            INDEX `idx_cge_facility` (`facility_id`),
            CONSTRAINT `fk_cge_carnet` FOREIGN KEY (`carnet_id`) REFERENCES `carnets`(`id`),
            CONSTRAINT `fk_cge_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `carnet_guest_entries`;
        ALTER TABLE `carnets` DROP COLUMN `used_invitations`, DROP COLUMN `total_invitations`
    ",
];
