-- Tabelas de Picking/Separação de Pedidos

-- Lista de picking
CREATE TABLE IF NOT EXISTS wms_picking_list (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    sales_order_id INT UNSIGNED NOT NULL,
    status ENUM("aberto", "em_separacao", "concluido", "cancelado") NOT NULL DEFAULT "aberto",
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    concluido_em DATETIME NULL,
    INDEX idx_sales_order (sales_order_id),
    INDEX idx_status (status),
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Itens da lista de picking
CREATE TABLE IF NOT EXISTS wms_picking_list_items (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    picking_list_id INT UNSIGNED NOT NULL,
    product_id INT UNSIGNED NOT NULL,
    quantidade DECIMAL(12,3) NOT NULL,
    quantidade_separada DECIMAL(12,3) NOT NULL DEFAULT 0,
    bin_id INT UNSIGNED NULL,
    bin_code VARCHAR(64) NULL,
    ordem INT UNSIGNED NOT NULL,
    status ENUM("pendente", "separado", "parcial", "sem_estoque", "estoque_insuficiente") NOT NULL DEFAULT "pendente",
    separado_em DATETIME NULL,
    INDEX idx_picking_list (picking_list_id),
    INDEX idx_product (product_id),
    INDEX idx_bin (bin_id),
    INDEX idx_status (status),
    INDEX idx_ordem (ordem)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

