<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `bank_reconciliations` (
            `id`                   BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `bank_account_id`      BIGINT UNSIGNED NOT NULL,
            `reconciliation_date`  DATE            NOT NULL,
            `statement_date`       DATE            NOT NULL,
            `statement_balance`    DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `book_balance`         DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `adjusted_balance`     DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `difference`           DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `status`               ENUM('draft','in_progress','completed','approved') NOT NULL DEFAULT 'draft',
            `approved_at`          DATETIME        NULL,
            `approved_by`          BIGINT UNSIGNED NULL,
            `notes`                TEXT            NULL,
            `is_archived`          TINYINT(1)      NOT NULL DEFAULT 0,
            `archived_at`          DATETIME        NULL,
            `archived_by`          BIGINT UNSIGNED NULL,
            `created_at`           DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`           DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`           BIGINT UNSIGNED NULL,
            `updated_by`           BIGINT UNSIGNED NULL,

            INDEX `idx_br_bank_account`   (`bank_account_id`),
            INDEX `idx_br_status`          (`status`),
            INDEX `idx_br_recon_date`      (`reconciliation_date`),
            CONSTRAINT `fk_br_bank_account` FOREIGN KEY (`bank_account_id`) REFERENCES `bank_accounts`(`id`),
            CONSTRAINT `fk_br_approved_by`  FOREIGN KEY (`approved_by`)     REFERENCES `employees`(`id`),
            CONSTRAINT `fk_br_created_by`   FOREIGN KEY (`created_by`)      REFERENCES `employees`(`id`),
            CONSTRAINT `fk_br_updated_by`   FOREIGN KEY (`updated_by`)      REFERENCES `employees`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `bank_reconciliations`",
];
