<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `business_rules` (
            `id`                 BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `rule_code`          VARCHAR(100) NOT NULL,
            `category`           VARCHAR(50) NOT NULL,
            `name_ar`            VARCHAR(300) NOT NULL,
            `name_en`            VARCHAR(300) NULL,
            `description_ar`     TEXT NULL,
            `description_en`     TEXT NULL,
            `parameters_json`    JSON NULL,
            `current_value_json` JSON NOT NULL,
            `data_type`          VARCHAR(50) NOT NULL DEFAULT 'string',
            `branch_id`          BIGINT UNSIGNED NULL,
            `effective_from`     DATE NOT NULL,
            `effective_to`       DATE NULL DEFAULT NULL,
            `is_active`          TINYINT(1) NOT NULL DEFAULT 1,
            `version`            INT UNSIGNED 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,
            `updated_by`         BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_business_rules_code_branch` (`rule_code`, `branch_id`),
            INDEX `idx_business_rules_category` (`category`),
            INDEX `idx_business_rules_branch` (`branch_id`),
            INDEX `idx_business_rules_active` (`is_active`),
            INDEX `idx_business_rules_effective` (`effective_from`, `effective_to`),
            CONSTRAINT `fk_business_rules_branch` FOREIGN KEY (`branch_id`) REFERENCES `branches`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `business_rules`",
];