<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `account_budgets` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `fiscal_year_id`  BIGINT UNSIGNED NOT NULL,
            `account_id`      BIGINT UNSIGNED NOT NULL,
            `period`          VARCHAR(7)      NOT NULL COMMENT 'YYYY-MM',
            `budgeted_amount` DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `notes`           TEXT            NULL,
            `created_by`      BIGINT UNSIGNED NULL,
            `created_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

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