CREATE PROCEDURE import_product(
    IN p_product_id BIGINT,
    IN p_title VARCHAR(255),
    IN p_SKU VARCHAR(50),
    IN p_created_at TIMESTAMP,
    IN p_stock_quantity INT,
    IN p_price DECIMAL(10, 3),
    IN p_regular_price DECIMAL(10, 3),
    IN p_cost_price DECIMAL(10, 3),
    IN p_landing_cost_price DECIMAL(10, 3),
    IN p_barcode VARCHAR(50),
    IN p_updated_at TIMESTAMP,
    IN p_visible BOOLEAN,
    IN p_managing_stock BOOLEAN,
    IN p_replenishable BOOLEAN,
    IN p_vendor VARCHAR(100),
    IN p_vendor_reference VARCHAR(100),
    IN p_permalink VARCHAR(255),
    IN p_categories TEXT,
    IN p_image VARCHAR(255),
    IN p_brand VARCHAR(100),
    IN p_options TEXT,
    IN p_tags TEXT,
    IN p_moq INT,
    IN p_uom INT
)
BEGIN
    INSERT INTO products 
    VALUES (
        p_product_id, p_title, p_SKU, p_created_at, p_stock_quantity,
        p_price, p_regular_price, p_cost_price, p_landing_cost_price,
        p_barcode, p_updated_at, p_visible, p_managing_stock,
        p_replenishable, p_vendor, p_vendor_reference, p_permalink,
        p_categories, p_image, p_brand, p_options, p_tags, p_moq, p_uom
    )
    ON DUPLICATE KEY UPDATE
        title = p_title,
        stock_quantity = p_stock_quantity,
        price = p_price,
        regular_price = p_regular_price,
        cost_price = p_cost_price,
        landing_cost_price = p_landing_cost_price,
        barcode = p_barcode,
        updated_at = p_updated_at,
        visible = p_visible,
        managing_stock = p_managing_stock,
        replenishable = p_replenishable,
        vendor = p_vendor,
        vendor_reference = p_vendor_reference,
        permalink = p_permalink,
        categories = p_categories,
        image = p_image,
        brand = p_brand,
        options = p_options,
        tags = p_tags,
        moq = p_moq,
        uom = p_uom;
END;

CREATE PROCEDURE import_order(
    IN p_order_number VARCHAR(50),
    IN p_product_id BIGINT,
    IN p_SKU VARCHAR(50),
    IN p_date DATE,
    IN p_price DECIMAL(10, 3),
    IN p_quantity INT,
    IN p_discount DECIMAL(10, 3),
    IN p_tax DECIMAL(10, 3),
    IN p_tax_included BOOLEAN,
    IN p_shipping DECIMAL(10, 3),
    IN p_customer VARCHAR(50),
    IN p_canceled BOOLEAN
)
BEGIN
    INSERT INTO orders (
        order_number, product_id, SKU, date, price, quantity,
        discount, tax, tax_included, shipping, customer, canceled
    )
    VALUES (
        p_order_number, p_product_id, p_SKU, p_date, p_price,
        p_quantity, p_discount, p_tax, p_tax_included, p_shipping,
        p_customer, p_canceled
    )
    ON DUPLICATE KEY UPDATE
        price = p_price,
        quantity = p_quantity,
        discount = p_discount,
        tax = p_tax,
        tax_included = p_tax_included,
        shipping = p_shipping,
        canceled = p_canceled;
END;

CREATE PROCEDURE import_purchase_order(
    IN p_po_id VARCHAR(50),
    IN p_vendor VARCHAR(100),
    IN p_date DATE,
    IN p_expected_date DATE,
    IN p_product_id BIGINT,
    IN p_sku VARCHAR(50),
    IN p_cost_price DECIMAL(10, 3),
    IN p_status VARCHAR(20),
    IN p_notes TEXT,
    IN p_ordered INT,
    IN p_received INT,
    IN p_received_date DATE
)
BEGIN
    INSERT INTO purchase_orders (
        po_id, vendor, date, expected_date, product_id, sku,
        cost_price, status, notes, ordered, received, received_date
    )
    VALUES (
        p_po_id, p_vendor, p_date, p_expected_date, p_product_id,
        p_sku, p_cost_price, p_status, p_notes, p_ordered,
        p_received, p_received_date
    )
    ON DUPLICATE KEY UPDATE
        vendor = p_vendor,
        expected_date = p_expected_date,
        cost_price = p_cost_price,
        status = p_status,
        notes = p_notes,
        ordered = p_ordered,
        received = p_received,
        received_date = p_received_date;
END; 