<?php
declare(strict_types=1);

return [
    'up' => "
CREATE TABLE IF NOT EXISTS instrument_status_history (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    instrument_id INT UNSIGNED NOT NULL,
    from_status VARCHAR(30) NULL,
    to_status VARCHAR(30) NOT NULL,
    transition_date DATE NOT NULL,
    bank_account_id INT UNSIGNED NULL,
    endorsed_to VARCHAR(255) NULL,
    bounce_reason VARCHAR(500) NULL,
    notes TEXT NULL,
    created_by INT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_instrument (instrument_id),
    KEY idx_date (transition_date),
    KEY idx_status (to_status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE negotiable_instruments ADD COLUMN deposited_date DATE NULL AFTER due_date;
ALTER TABLE negotiable_instruments ADD COLUMN collected_date DATE NULL AFTER deposited_date;
ALTER TABLE negotiable_instruments ADD COLUMN bounced_date DATE NULL AFTER collected_date;
ALTER TABLE negotiable_instruments ADD COLUMN bounce_reason VARCHAR(500) NULL AFTER bounced_date;
ALTER TABLE negotiable_instruments ADD COLUMN endorsed_to VARCHAR(255) NULL AFTER bounce_reason;
ALTER TABLE negotiable_instruments ADD COLUMN endorsed_date DATE NULL AFTER endorsed_to;
ALTER TABLE negotiable_instruments ADD COLUMN portfolio_id INT UNSIGNED NULL AFTER endorsed_date",
    'down' => "
ALTER TABLE negotiable_instruments DROP COLUMN portfolio_id;
ALTER TABLE negotiable_instruments DROP COLUMN endorsed_date;
ALTER TABLE negotiable_instruments DROP COLUMN endorsed_to;
ALTER TABLE negotiable_instruments DROP COLUMN bounce_reason;
ALTER TABLE negotiable_instruments DROP COLUMN bounced_date;
ALTER TABLE negotiable_instruments DROP COLUMN collected_date;
ALTER TABLE negotiable_instruments DROP COLUMN deposited_date;
DROP TABLE IF EXISTS instrument_status_history",
];
