<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `stock_audits` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `audit_number`    VARCHAR(50) NOT NULL,
            `warehouse_id`    BIGINT UNSIGNED NOT NULL,
            `audit_type`      VARCHAR(20) NOT NULL COMMENT 'full, partial, spot_check',
            `category_id`     BIGINT UNSIGNED NULL,
            `status`          VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, in_progress, pending_approval, approved, cancelled',
            `audit_date`      DATE NOT NULL,
            `started_at`      TIMESTAMP NULL DEFAULT NULL,
            `completed_at`    TIMESTAMP NULL DEFAULT NULL,
            `approved_by`     BIGINT UNSIGNED NULL,
            `approved_at`     TIMESTAMP NULL DEFAULT NULL,
            `total_items`     INT UNSIGNED NOT NULL DEFAULT 0,
            `items_counted`   INT UNSIGNED NOT NULL DEFAULT 0,
            `variance_count`  INT UNSIGNED NOT NULL DEFAULT 0,
            `notes`           TEXT NULL,
            `branch_id`       BIGINT UNSIGNED NULL,
            `is_archived`     TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`     TIMESTAMP NULL DEFAULT NULL,
            `archived_by`     BIGINT UNSIGNED 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,
            `updated_by`      BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_stock_audits_number` (`audit_number`),
            INDEX `idx_sa_warehouse` (`warehouse_id`),
            INDEX `idx_sa_status` (`status`),
            INDEX `idx_sa_type` (`audit_type`),
            INDEX `idx_sa_date` (`audit_date`),
            CONSTRAINT `fk_sa_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_sa_category` FOREIGN KEY (`category_id`) REFERENCES `item_categories`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `stock_audits`",
];
