<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE `sa_booking_changes` (
            `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `booking_id` BIGINT UNSIGNED NOT NULL,
            `change_type` VARCHAR(30) NOT NULL COMMENT 'postponed, cancelled, time_changed, unit_changed',
            `old_date` DATE NULL,
            `new_date` DATE NULL,
            `old_start_time` TIME NULL,
            `new_start_time` TIME NULL,
            `old_end_time` TIME NULL,
            `new_end_time` TIME NULL,
            `old_unit_id` BIGINT UNSIGNED NULL,
            `new_unit_id` BIGINT UNSIGNED NULL,
            `reason` TEXT NULL,
            `changed_by` BIGINT UNSIGNED NULL,
            `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_sa_bc_booking` (`booking_id`),
            INDEX `idx_sa_bc_type` (`change_type`),
            CONSTRAINT `fk_sa_bc_booking` FOREIGN KEY (`booking_id`) REFERENCES `sa_bookings`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
        ALTER TABLE sa_bookings ADD COLUMN postponed_count TINYINT UNSIGNED NOT NULL DEFAULT 0 AFTER cancellation_reason;
        ALTER TABLE sa_bookings ADD COLUMN original_date DATE NULL AFTER postponed_count;
        ALTER TABLE sa_bookings ADD COLUMN original_start_time TIME NULL AFTER original_date;
    ",
    'down' => "
        DROP TABLE IF EXISTS `sa_booking_changes`;
        ALTER TABLE sa_bookings DROP COLUMN postponed_count;
        ALTER TABLE sa_bookings DROP COLUMN original_date;
        ALTER TABLE sa_bookings DROP COLUMN original_start_time;
    ",
];
