<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `bank_accounts` (
            `id`               BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `account_name_ar`  VARCHAR(200)    NOT NULL,
            `account_name_en`  VARCHAR(200)    NOT NULL,
            `bank_name_ar`     VARCHAR(200)    NOT NULL,
            `bank_name_en`     VARCHAR(200)    NULL,
            `account_number`   VARCHAR(50)     NOT NULL,
            `iban`             VARCHAR(34)     NULL,
            `swift_code`       VARCHAR(11)     NULL,
            `branch_name`      VARCHAR(150)    NULL,
            `currency`         VARCHAR(3)      NOT NULL DEFAULT 'EGP',
            `gl_account_id`    BIGINT UNSIGNED NULL COMMENT 'Linked chart_of_accounts entry',
            `opening_balance`  DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `current_balance`  DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `is_default`       TINYINT(1)      NOT NULL DEFAULT 0,
            `is_active`        TINYINT(1)      NOT NULL DEFAULT 1,
            `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,

            UNIQUE INDEX `idx_ba_account_number` (`account_number`),
            INDEX `idx_ba_gl_account`             (`gl_account_id`),
            INDEX `idx_ba_is_active`              (`is_active`),
            CONSTRAINT `fk_ba_gl_account`  FOREIGN KEY (`gl_account_id`) REFERENCES `chart_of_accounts`(`id`),
            CONSTRAINT `fk_ba_created_by`  FOREIGN KEY (`created_by`)    REFERENCES `employees`(`id`),
            CONSTRAINT `fk_ba_updated_by`  FOREIGN KEY (`updated_by`)    REFERENCES `employees`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `bank_accounts`",
];
