<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `negotiable_instruments` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `instrument_type`   ENUM('check','promissory_note') NOT NULL DEFAULT 'check',
            `direction`         ENUM('receivable','payable') NOT NULL,
            `instrument_number` VARCHAR(50)     NOT NULL,
            `amount`            DECIMAL(18,2)   NOT NULL,
            `currency`          VARCHAR(3)      NOT NULL DEFAULT 'EGP',
            `issue_date`        DATE            NOT NULL,
            `due_date`          DATE            NOT NULL,
            `drawer_name`       VARCHAR(200)    NULL COMMENT 'الساحب',
            `drawer_bank`       VARCHAR(200)    NULL,
            `beneficiary_name`  VARCHAR(200)    NULL COMMENT 'المستفيد',
            `endorsee_name`     VARCHAR(200)    NULL COMMENT 'المظهر إليه',
            `status`            ENUM('in_hand','under_collection','collected','bounced','endorsed','cancelled','paid','returned') NOT NULL DEFAULT 'in_hand',
            `current_location`  ENUM('safe','bank','endorsed_to','returned_to_drawer') NOT NULL DEFAULT 'safe',
            `bank_account_id`   BIGINT UNSIGNED NULL,
            `member_id`         BIGINT UNSIGNED NULL,
            `vendor_id`         BIGINT UNSIGNED NULL,
            `payment_id`        BIGINT UNSIGNED NULL COMMENT 'Source payment record',
            `journal_entry_id`  BIGINT UNSIGNED NULL,
            `notes`             TEXT            NULL,
            `is_archived`       TINYINT(1)      NOT NULL DEFAULT 0,
            `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_ni_status` (`status`),
            INDEX `idx_ni_due_date` (`due_date`),
            INDEX `idx_ni_direction` (`direction`),
            INDEX `idx_ni_member` (`member_id`),
            INDEX `idx_ni_vendor` (`vendor_id`),
            INDEX `idx_ni_bank` (`bank_account_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `negotiable_instruments`",
];
