DROP PROCEDURE IF EXISTS `get_product_with_id`;
DELIMITER ;;
CREATE PROCEDURE `get_product_with_id` (
    IN p_product_id INT
)
proc:BEGIN
    DECLARE v_seller_id INT;
    IF (SELECT COUNT(id) FROM products WHERE id = p_product_id) = 0 OR p_product_id IS NULL THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'get_product_with_id: Product does not exist';
        LEAVE proc;
    END IF;
    SELECT user_id INTO v_seller_id FROM products WHERE id = p_product_id;
    SELECT * FROM products WHERE id = p_product_id AND pending = false AND archived = false;
    SELECT id, name, username, picture FROM users WHERE id = v_seller_id;
END ;;
DELIMITER ;
