<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `account_balances` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `account_id`      BIGINT UNSIGNED NOT NULL,
            `fiscal_year_id`  BIGINT UNSIGNED NOT NULL,
            `period`          VARCHAR(7)      NOT NULL COMMENT 'YYYY-MM format',
            `opening_debit`   DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `opening_credit`  DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `period_debit`    DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `period_credit`   DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `closing_debit`   DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `closing_credit`  DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `cost_center_id`  BIGINT UNSIGNED NULL,
            `branch_id`       BIGINT UNSIGNED NULL,
            `is_closed`       TINYINT(1)      NOT NULL DEFAULT 0,
            `created_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

            UNIQUE INDEX `idx_ab_unique` (`account_id`, `fiscal_year_id`, `period`, `cost_center_id`, `branch_id`),
            INDEX `idx_ab_fiscal_year`   (`fiscal_year_id`),
            INDEX `idx_ab_period`        (`period`),
            INDEX `idx_ab_cost_center`   (`cost_center_id`),
            INDEX `idx_ab_branch`        (`branch_id`),
            CONSTRAINT `fk_ab_account`      FOREIGN KEY (`account_id`)     REFERENCES `chart_of_accounts`(`id`),
            CONSTRAINT `fk_ab_fiscal_year`  FOREIGN KEY (`fiscal_year_id`) REFERENCES `fiscal_years`(`id`),
            CONSTRAINT `fk_ab_cost_center`  FOREIGN KEY (`cost_center_id`) REFERENCES `cost_centers`(`id`),
            CONSTRAINT `fk_ab_branch`       FOREIGN KEY (`branch_id`)      REFERENCES `branches`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `account_balances`",
];
