<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `rental_bookings` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `contract_id`       BIGINT UNSIGNED NOT NULL,
            `facility_id`       BIGINT UNSIGNED NOT NULL,
            `booking_date`      DATE NOT NULL,
            `start_time`        TIME NOT NULL,
            `end_time`          TIME NOT NULL,
            `status`            VARCHAR(20) NOT NULL DEFAULT 'scheduled' COMMENT 'scheduled, completed, cancelled, no_show',
            `notes`             TEXT NULL,
            `created_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX `idx_rb_contract` (`contract_id`),
            INDEX `idx_rb_facility` (`facility_id`),
            INDEX `idx_rb_date` (`booking_date`),
            INDEX `idx_rb_facility_date` (`facility_id`, `booking_date`, `start_time`, `end_time`),
            CONSTRAINT `fk_rb_contract` FOREIGN KEY (`contract_id`) REFERENCES `rental_contracts`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_rb_facility` FOREIGN KEY (`facility_id`) REFERENCES `facilities`(`id`) ON DELETE RESTRICT
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `rental_bookings`",
];
