<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `rule_overrides` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `rule_id`             BIGINT UNSIGNED NOT NULL,
            `entity_type`         VARCHAR(100) NOT NULL,
            `entity_id`           BIGINT UNSIGNED NOT NULL,
            `override_value_json` JSON NOT NULL,
            `reason`              TEXT NOT NULL,
            `approved_by`         BIGINT UNSIGNED NULL,
            `effective_from`      DATE NOT NULL,
            `effective_to`        DATE NULL DEFAULT NULL,
            `is_active`           TINYINT(1) NOT NULL DEFAULT 1,
            `created_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_rule_overrides_rule` (`rule_id`),
            INDEX `idx_rule_overrides_entity` (`entity_type`, `entity_id`),
            CONSTRAINT `fk_rule_overrides_rule` FOREIGN KEY (`rule_id`) REFERENCES `business_rules`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `rule_overrides`",
];