CREATE TABLE IF NOT EXISTS products (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    codigo VARCHAR(100) NOT NULL,
    ean VARCHAR(20),
    ncm VARCHAR(10),
    pis VARCHAR(10),
    cofins VARCHAR(10),
    cest VARCHAR(10),
    cfop VARCHAR(10),
    estoque DECIMAL(18,3) DEFAULT 0,
    preco DECIMAL(18,2) DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS inventory_movements (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    product_id BIGINT UNSIGNED NOT NULL,
    tipo VARCHAR(20) NOT NULL,
    quantidade DECIMAL(18,3) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (product_id) REFERENCES products(id)
);