<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `return_to_vendor` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `rtv_number`          VARCHAR(50) NOT NULL COMMENT 'RTV-YYYY-NNNNNN',
            `supplier_id`         BIGINT UNSIGNED NOT NULL COMMENT 'FK suppliers.id',
            `grn_id`              BIGINT UNSIGNED NULL COMMENT 'FK goods_received_notes.id',
            `purchase_order_id`   BIGINT UNSIGNED NULL COMMENT 'FK purchase_orders.id',
            `warehouse_id`        BIGINT UNSIGNED NOT NULL COMMENT 'FK warehouses.id',
            `reason`              TEXT NOT NULL,
            `return_date`         DATE NOT NULL,
            `status`              VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft,submitted,approved,shipped,completed,cancelled',
            `total_amount`        DECIMAL(18,2) NOT NULL DEFAULT 0.00,
            `debit_note_number`   VARCHAR(100) NULL,
            `debit_note_amount`   DECIMAL(18,2) NULL,
            `debit_note_date`     DATE NULL,
            `journal_entry_id`    BIGINT UNSIGNED NULL COMMENT 'FK journal_entries.id',
            `approved_by`         BIGINT UNSIGNED NULL,
            `approved_at`         DATETIME NULL,
            `shipped_by`          BIGINT UNSIGNED NULL,
            `shipped_at`          DATETIME NULL,
            `completed_by`        BIGINT UNSIGNED NULL,
            `completed_at`        DATETIME NULL,
            `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_rtv_number` (`rtv_number`),
            INDEX `idx_rtv_supplier` (`supplier_id`),
            INDEX `idx_rtv_grn` (`grn_id`),
            INDEX `idx_rtv_warehouse` (`warehouse_id`),
            INDEX `idx_rtv_status` (`status`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `return_to_vendor`",
];
