<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `instrument_portfolios` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `portfolio_number`  VARCHAR(30)     NOT NULL,
            `portfolio_type`    ENUM('deposit','collection','payment','endorsement','return','bounce') NOT NULL,
            `portfolio_date`    DATE            NOT NULL,
            `bank_account_id`   BIGINT UNSIGNED NULL,
            `total_amount`      DECIMAL(18,2)   NOT NULL DEFAULT 0.00,
            `instrument_count`  INT UNSIGNED    NOT NULL DEFAULT 0,
            `description`       TEXT            NULL,
            `branch_id`         BIGINT UNSIGNED NULL,
            `journal_entry_id`  BIGINT UNSIGNED NULL,
            `status`            ENUM('draft','confirmed') NOT NULL DEFAULT 'draft',
            `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,

            INDEX `idx_port_type` (`portfolio_type`),
            INDEX `idx_port_date` (`portfolio_date`),
            INDEX `idx_port_status` (`status`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

        CREATE TABLE IF NOT EXISTS `instrument_portfolio_items` (
            `id`            BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `portfolio_id`  BIGINT UNSIGNED NOT NULL,
            `instrument_id` BIGINT UNSIGNED NOT NULL,

            FOREIGN KEY (`portfolio_id`) REFERENCES `instrument_portfolios`(`id`) ON DELETE CASCADE,
            FOREIGN KEY (`instrument_id`) REFERENCES `negotiable_instruments`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "
        DROP TABLE IF EXISTS `instrument_portfolio_items`;
        DROP TABLE IF EXISTS `instrument_portfolios`
    ",
];
