<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `goods_received_notes` (
            `id`                 BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `grn_number`         VARCHAR(50) NOT NULL,
            `purchase_order_id`  BIGINT UNSIGNED NOT NULL COMMENT 'FK purchase_orders.id',
            `supplier_id`        BIGINT UNSIGNED NOT NULL COMMENT 'FK suppliers.id',
            `warehouse_id`       BIGINT UNSIGNED NOT NULL COMMENT 'FK warehouses.id',
            `received_by`        BIGINT UNSIGNED NULL COMMENT 'FK employees.id',
            `received_date`      DATE NOT NULL,
            `status`             VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT 'draft,inspecting,accepted,partial_accept,cancelled',
            `total_received_value` DECIMAL(18,2) NOT NULL DEFAULT 0.00,
            `total_accepted_value` DECIMAL(18,2) NOT NULL DEFAULT 0.00,
            `inspection_notes`   TEXT NULL,
            `notes`              TEXT NULL,
            `branch_id`          BIGINT UNSIGNED NULL,
            `is_archived`        TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`        DATETIME NULL,
            `archived_by`        BIGINT UNSIGNED NULL,
            `created_at`         DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`         DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`         BIGINT UNSIGNED NULL,
            `updated_by`         BIGINT UNSIGNED NULL,
            UNIQUE INDEX `uq_grn_number` (`grn_number`),
            INDEX `idx_grn_po` (`purchase_order_id`),
            INDEX `idx_grn_supplier` (`supplier_id`),
            INDEX `idx_grn_warehouse` (`warehouse_id`),
            INDEX `idx_grn_status` (`status`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `goods_received_notes`",
];
