<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `grn_items` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `grn_id`              BIGINT UNSIGNED NOT NULL,
            `po_item_id`          BIGINT UNSIGNED NOT NULL COMMENT 'FK purchase_order_items.id',
            `item_id`             BIGINT UNSIGNED NOT NULL COMMENT 'FK inventory_items.id',
            `quantity_received`   DECIMAL(15,3) NOT NULL,
            `quantity_accepted`   DECIMAL(15,3) NOT NULL DEFAULT 0.000,
            `quantity_rejected`   DECIMAL(15,3) NOT NULL DEFAULT 0.000,
            `rejection_reason`    TEXT NULL,
            `batch_number`        VARCHAR(100) NULL,
            `expiry_date`         DATE NULL,
            `unit_cost`           DECIMAL(18,2) NOT NULL,
            `line_total`          DECIMAL(18,2) NOT NULL,
            `notes`               TEXT NULL,
            INDEX `idx_grni_grn` (`grn_id`),
            INDEX `idx_grni_po_item` (`po_item_id`),
            INDEX `idx_grni_item` (`item_id`),
            CONSTRAINT `fk_grni_grn` FOREIGN KEY (`grn_id`) REFERENCES `goods_received_notes`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `grn_items`",
];
