<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `purchase_order_items` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `purchase_order_id` BIGINT UNSIGNED NOT NULL,
            `item_id`           BIGINT UNSIGNED NOT NULL,
            `quantity_ordered`  DECIMAL(15,3) NOT NULL,
            `quantity_received` DECIMAL(15,3) NOT NULL DEFAULT 0.000,
            `unit_cost`         DECIMAL(15,2) NOT NULL,
            `tax_rate`          DECIMAL(5,2) NOT NULL DEFAULT 0.00,
            `line_total`        DECIMAL(15,2) NOT NULL,
            `notes`             TEXT NULL,
            INDEX `idx_poi_po` (`purchase_order_id`),
            INDEX `idx_poi_item` (`item_id`),
            CONSTRAINT `fk_poi_po` FOREIGN KEY (`purchase_order_id`) REFERENCES `purchase_orders`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_poi_item` FOREIGN KEY (`item_id`) REFERENCES `inventory_items`(`id`) ON DELETE RESTRICT
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `purchase_order_items`",
];
