<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `item_warehouse_stock` (
            `id`               BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `item_id`          BIGINT UNSIGNED NOT NULL,
            `warehouse_id`     BIGINT UNSIGNED NOT NULL,
            `quantity`         DECIMAL(15,3) NOT NULL DEFAULT 0.000,
            `min_level`        DECIMAL(15,3) NULL,
            `max_level`        DECIMAL(15,3) NULL,
            `last_counted_at`  TIMESTAMP NULL,
            `updated_at`       TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            UNIQUE KEY `uq_item_warehouse_stock_item_warehouse` (`item_id`, `warehouse_id`),
            INDEX `idx_item_warehouse_stock_warehouse` (`warehouse_id`),
            INDEX `idx_item_warehouse_stock_quantity` (`quantity`),
            CONSTRAINT `fk_item_warehouse_stock_item` FOREIGN KEY (`item_id`) REFERENCES `inventory_items` (`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_item_warehouse_stock_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `item_warehouse_stock`",
];
