<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `purchase_requisitions` (
            `id`                 BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `pr_number`          VARCHAR(50) NOT NULL,
            `requested_by`       BIGINT UNSIGNED NOT NULL COMMENT 'FK employees.id',
            `department`         VARCHAR(100) NULL,
            `status`             VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft,submitted,approved,rejected,converted,cancelled',
            `urgency`            ENUM('low','normal','high','critical') NOT NULL DEFAULT 'normal',
            `required_date`      DATE NULL,
            `justification`      TEXT NULL,
            `estimated_total`    DECIMAL(18,2) NOT NULL DEFAULT 0.00,
            `approved_by`        BIGINT UNSIGNED NULL,
            `approved_at`        DATETIME NULL,
            `rejected_by`        BIGINT UNSIGNED NULL,
            `rejected_at`        DATETIME NULL,
            `rejection_reason`   TEXT NULL,
            `converted_po_id`    BIGINT UNSIGNED NULL COMMENT 'FK purchase_orders.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_pr_number` (`pr_number`),
            INDEX `idx_pr_status` (`status`),
            INDEX `idx_pr_requested_by` (`requested_by`),
            INDEX `idx_pr_branch` (`branch_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `purchase_requisitions`",
];
