<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `bank_reconciliation_items` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `reconciliation_id`     BIGINT UNSIGNED NOT NULL,
            `item_type`             ENUM('outstanding_check','deposit_in_transit','bank_charge','bank_interest','book_error','bank_error','other') NOT NULL,
            `description_ar`        VARCHAR(300)    NOT NULL,
            `description_en`        VARCHAR(300)    NULL,
            `amount`                DECIMAL(18,2)   NOT NULL,
            `transaction_date`      DATE            NULL,
            `reference_number`      VARCHAR(50)     NULL,
            `journal_entry_id`      BIGINT UNSIGNED NULL COMMENT 'Adjusting entry if created',
            `is_cleared`            TINYINT(1)      NOT NULL DEFAULT 0,
            `cleared_date`          DATE            NULL,
            `created_at`            DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,

            INDEX `idx_bri_reconciliation` (`reconciliation_id`),
            INDEX `idx_bri_type`           (`item_type`),
            INDEX `idx_bri_cleared`        (`is_cleared`),
            CONSTRAINT `fk_bri_reconciliation` FOREIGN KEY (`reconciliation_id`) REFERENCES `bank_reconciliations`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_bri_journal_entry`  FOREIGN KEY (`journal_entry_id`)  REFERENCES `journal_entries`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `bank_reconciliation_items`",
];
