DROP PROCEDURE IF EXISTS `check_if_product_belong_to_user`;
DELIMITER ;;
CREATE PROCEDURE `check_if_product_belong_to_user` (
    IN p_product_id INT,
    IN p_user_id INT,
    OUT p_return INT
)
proc:BEGIN
    DECLARE v_ret INT;
    CALL check_if_product_exists(p_product_id, v_ret);
    IF v_ret != 0 THEN
        SET p_return = -2;
        LEAVE proc;
    END IF;
    IF (SELECT COUNT(id) FROM products WHERE id = p_product_id AND user_id = p_user_id) = 0 THEN
        SET p_return = -1;
        LEAVE proc;
    END IF;
    SET p_return = 0;
END ;;
DELIMITER ;
