<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `stock_audit_items` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `audit_id`          BIGINT UNSIGNED NOT NULL,
            `item_id`           BIGINT UNSIGNED NOT NULL,
            `batch_id`          BIGINT UNSIGNED NULL,
            `system_quantity`   DECIMAL(15,3) NOT NULL,
            `physical_quantity` DECIMAL(15,3) NULL,
            `variance`          DECIMAL(15,3) NULL,
            `variance_cost`     DECIMAL(15,2) NULL,
            `status`            VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending, counted, approved, skipped',
            `counted_by`        BIGINT UNSIGNED NULL,
            `counted_at`        TIMESTAMP NULL DEFAULT NULL,
            `notes`             TEXT NULL,
            INDEX `idx_stock_audit_items_audit` (`audit_id`),
            INDEX `idx_stock_audit_items_item` (`item_id`),
            INDEX `idx_stock_audit_items_status` (`status`),
            CONSTRAINT `fk_stock_audit_items_audit` FOREIGN KEY (`audit_id`) REFERENCES `stock_audits`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_stock_audit_items_item` FOREIGN KEY (`item_id`) REFERENCES `inventory_items`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_stock_audit_items_batch` FOREIGN KEY (`batch_id`) REFERENCES `item_batches`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `stock_audit_items`",
];
