<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `vendor_payments` (
            `id`                 BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `payment_number`     VARCHAR(50) NOT NULL COMMENT 'VPAY-YYYY-NNNNNN',
            `supplier_id`        BIGINT UNSIGNED NOT NULL COMMENT 'FK suppliers.id',
            `invoice_id`         BIGINT UNSIGNED NULL COMMENT 'FK vendor_invoices.id',
            `amount`             DECIMAL(18,2) NOT NULL,
            `currency`           VARCHAR(3) NOT NULL DEFAULT 'EGP',
            `payment_method`     VARCHAR(30) NOT NULL COMMENT 'cash,bank_transfer,check,wire',
            `bank_account_id`    BIGINT UNSIGNED NULL COMMENT 'FK bank_accounts.id',
            `check_number`       VARCHAR(50) NULL,
            `reference_number`   VARCHAR(100) NULL,
            `payment_date`       DATE NOT NULL,
            `status`             VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft,approved,completed,voided',
            `approved_by`        BIGINT UNSIGNED NULL,
            `approved_at`        DATETIME NULL,
            `completed_by`       BIGINT UNSIGNED NULL,
            `completed_at`       DATETIME NULL,
            `voided_by`          BIGINT UNSIGNED NULL,
            `voided_at`          DATETIME NULL,
            `void_reason`        TEXT NULL,
            `journal_entry_id`   BIGINT UNSIGNED NULL COMMENT 'FK journal_entries.id',
            `notes`              TEXT NULL,
            `branch_id`          BIGINT UNSIGNED NULL,
            `is_archived`        TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`        DATETIME NULL,
            `archived_by`        BIGINT UNSIGNED NULL,
            `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,
            `updated_by`         BIGINT UNSIGNED NULL,
            UNIQUE INDEX `uq_vpay_number` (`payment_number`),
            INDEX `idx_vpay_supplier` (`supplier_id`),
            INDEX `idx_vpay_invoice` (`invoice_id`),
            INDEX `idx_vpay_status` (`status`),
            INDEX `idx_vpay_date` (`payment_date`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `vendor_payments`",
];
