<?php
declare(strict_types=1);

return [
    'up' => "CREATE TABLE `sa_pricing_rules` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `facility_unit_id` BIGINT UNSIGNED NOT NULL,
    `time_bracket_id` BIGINT UNSIGNED NOT NULL,
    `group_size_min` INT UNSIGNED NOT NULL DEFAULT 1,
    `group_size_max` INT UNSIGNED NOT NULL DEFAULT 1,
    `price_per_person_member` DECIMAL(10,2) NOT NULL,
    `price_per_person_nonmember` DECIMAL(10,2) NOT NULL,
    `effective_from` DATE NOT NULL,
    `effective_to` DATE NULL,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `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,
    INDEX `idx_sa_pr_unit` (`facility_unit_id`),
    INDEX `idx_sa_pr_bracket` (`time_bracket_id`),
    INDEX `idx_sa_pr_active` (`is_active`, `effective_from`, `effective_to`),
    UNIQUE KEY `uq_sa_pr_rule` (`facility_unit_id`, `time_bracket_id`, `group_size_min`, `group_size_max`, `effective_from`),
    CONSTRAINT `fk_sa_pr_unit` FOREIGN KEY (`facility_unit_id`) REFERENCES `sa_facility_units`(`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_sa_pr_bracket` FOREIGN KEY (`time_bracket_id`) REFERENCES `sa_time_brackets`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
    'down' => "DROP TABLE IF EXISTS `sa_pricing_rules`;"
];
