<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `stock_transfers` (
            `id`                BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `transfer_number`   VARCHAR(50) NOT NULL,
            `from_warehouse_id` BIGINT UNSIGNED NOT NULL,
            `to_warehouse_id`   BIGINT UNSIGNED NOT NULL,
            `status`            VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft, pending_approval, approved, in_transit, received, cancelled',
            `requested_by`      BIGINT UNSIGNED NULL,
            `approved_by`       BIGINT UNSIGNED NULL,
            `approved_at`       TIMESTAMP NULL DEFAULT NULL,
            `received_by`       BIGINT UNSIGNED NULL,
            `received_at`       TIMESTAMP NULL DEFAULT NULL,
            `transfer_date`     DATE NOT NULL,
            `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_transfers_number` (`transfer_number`),
            INDEX `idx_stock_transfers_from` (`from_warehouse_id`),
            INDEX `idx_stock_transfers_to` (`to_warehouse_id`),
            INDEX `idx_stock_transfers_status` (`status`),
            INDEX `idx_stock_transfers_date` (`transfer_date`),
            CONSTRAINT `fk_st_from_warehouse` FOREIGN KEY (`from_warehouse_id`) REFERENCES `warehouses`(`id`) ON DELETE RESTRICT,
            CONSTRAINT `fk_st_to_warehouse` FOREIGN KEY (`to_warehouse_id`) REFERENCES `warehouses`(`id`) ON DELETE RESTRICT
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `stock_transfers`",
];
