<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `accounting_dimensions` (
            `id`          BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `code`        VARCHAR(20)     NOT NULL,
            `name_ar`     VARCHAR(100)    NOT NULL,
            `name_en`     VARCHAR(100)    NOT NULL,
            `is_required` TINYINT(1)      NOT NULL DEFAULT 0,
            `is_active`   TINYINT(1)      NOT NULL DEFAULT 1,
            `created_at`  DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`  DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

            UNIQUE INDEX `idx_dim_code` (`code`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE IF NOT EXISTS `accounting_dimension_values` (
            `id`           BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `dimension_id` BIGINT UNSIGNED NOT NULL,
            `code`         VARCHAR(20)     NOT NULL,
            `name_ar`      VARCHAR(100)    NOT NULL,
            `name_en`      VARCHAR(100)    NOT NULL,
            `parent_id`    BIGINT UNSIGNED NULL,
            `is_active`    TINYINT(1)      NOT NULL DEFAULT 1,
            `created_at`   DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`   DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

            UNIQUE KEY `idx_dim_val_unique` (`dimension_id`, `code`),
            FOREIGN KEY (`dimension_id`) REFERENCES `accounting_dimensions`(`id`) ON DELETE CASCADE,
            FOREIGN KEY (`parent_id`) REFERENCES `accounting_dimension_values`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `accounting_dimension_values`;
        DROP TABLE IF EXISTS `accounting_dimensions`
    ",
];
