<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `historical_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 or YYYY for annual',
            `debit_total`     DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `credit_total`    DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `closing_balance` DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `created_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,

            UNIQUE KEY `idx_hist_unique` (`account_id`, `fiscal_year_id`, `period`),
            INDEX `idx_hist_year` (`fiscal_year_id`),
            FOREIGN KEY (`account_id`) REFERENCES `chart_of_accounts`(`id`),
            FOREIGN KEY (`fiscal_year_id`) REFERENCES `fiscal_years`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `historical_balances`",
];
