<?php
declare(strict_types=1);

return [
    'up' => "
CREATE TABLE `treasury_settlements` (
    `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `settlement_number`     VARCHAR(30) NOT NULL UNIQUE,
    `from_treasury_id`      BIGINT UNSIGNED NOT NULL,
    `to_treasury_id`        BIGINT UNSIGNED NOT NULL,
    `session_id`            BIGINT UNSIGNED NOT NULL,
    `amount`                DECIMAL(14,2) NOT NULL,
    `settled_by`            BIGINT UNSIGNED NOT NULL,
    `received_by`           BIGINT UNSIGNED NULL,
    `settled_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `received_at`           TIMESTAMP NULL,
    `status`                ENUM('pending','received','rejected') NOT NULL DEFAULT 'pending',
    `rejection_reason`      TEXT NULL,
    `receipt_count`         INT UNSIGNED NOT NULL DEFAULT 0,
    `journal_entry_id`      BIGINT UNSIGNED NULL,
    `notes`                 TEXT NULL,
    `created_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX `idx_settlements_from` (`from_treasury_id`),
    INDEX `idx_settlements_to` (`to_treasury_id`),
    INDEX `idx_settlements_session` (`session_id`),
    INDEX `idx_settlements_status` (`status`),
    CONSTRAINT `fk_settlements_from` FOREIGN KEY (`from_treasury_id`) REFERENCES `treasuries`(`id`),
    CONSTRAINT `fk_settlements_to` FOREIGN KEY (`to_treasury_id`) REFERENCES `treasuries`(`id`),
    CONSTRAINT `fk_settlements_session` FOREIGN KEY (`session_id`) REFERENCES `treasury_sessions`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
",
    'down' => "DROP TABLE IF EXISTS `treasury_settlements`",
];
