<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `item_batches` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `item_id`           BIGINT UNSIGNED NOT NULL,
            `warehouse_id`      BIGINT UNSIGNED NOT NULL,
            `batch_number`      VARCHAR(100) NOT NULL,
            `expiry_date`       DATE NOT NULL,
            `quantity`          DECIMAL(15,3) NOT NULL DEFAULT 0.000,
            `initial_quantity`  DECIMAL(15,3) NOT NULL,
            `unit_cost`         DECIMAL(15,2) NULL,
            `received_date`     DATE NOT NULL,
            `status`            VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT 'active, expired, depleted',
            `notes`             TEXT NULL,
            `created_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`        BIGINT UNSIGNED NULL,
            INDEX `idx_item_batches_item` (`item_id`),
            INDEX `idx_item_batches_warehouse` (`warehouse_id`),
            INDEX `idx_item_batches_expiry` (`expiry_date`),
            INDEX `idx_item_batches_status` (`status`),
            INDEX `idx_item_batches_item_warehouse` (`item_id`, `warehouse_id`),
            INDEX `idx_item_batches_batch_number` (`batch_number`),
            CONSTRAINT `fk_item_batches_item` FOREIGN KEY (`item_id`) REFERENCES `inventory_items` (`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_item_batches_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_batches`",
];
