DROP PROCEDURE IF EXISTS `remove_pending_product`;
DELIMITER ;;
CREATE PROCEDURE `remove_pending_product` (
    IN p_product_id INT,
    IN p_session_id CHAR(64)
)
proc:BEGIN
    -- must check if admin
    IF (SELECT COUNT(session_id) FROM sessions WHERE session_id = LOWER(p_session_id)) = 0 OR p_session_id IS NULL THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'remove_pending_product: No user logged in';
        LEAVE proc;
    END IF;
    SELECT user_id INTO @user_id FROM sessions WHERE session_id = LOWER(p_session_id);
    IF (SELECT COUNT(id) FROM products WHERE id = p_product_id) = 0 OR p_product_id IS NULL THEN
        SIGNAL SQLSTATE '45001' SET MESSAGE_TEXT = 'remove_pending_product: Product does not exist';
        LEAVE proc;
    END IF;
    UPDATE products SET archived = true WHERE id = p_product_id;
    SELECT 0 AS 'status', 'remove_pending_product' AS 'proc';
END ;;
DELIMITER ;
