<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `cost_center_budgets` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `fiscal_year_id`  BIGINT UNSIGNED NOT NULL,
            `cost_center_id`  BIGINT UNSIGNED NOT NULL,
            `account_id`      BIGINT UNSIGNED NULL COMMENT 'Optional: budget per account within cost center',
            `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_cc_budget_unique` (`fiscal_year_id`, `cost_center_id`, `account_id`, `period`),
            INDEX `idx_cc_budget_center` (`cost_center_id`),
            INDEX `idx_cc_budget_year` (`fiscal_year_id`),
            FOREIGN KEY (`fiscal_year_id`) REFERENCES `fiscal_years`(`id`),
            FOREIGN KEY (`cost_center_id`) REFERENCES `cost_centers`(`id`),
            FOREIGN KEY (`account_id`) REFERENCES `chart_of_accounts`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `cost_center_budgets`",
];
