DELIMITER //

CREATE PROCEDURE UpdateUserComplaintStatus (
    IN mobileNumber VARCHAR(20), 
    IN complaintStatus INT)   
BEGIN
    DECLARE sessionExists BOOLEAN DEFAULT FALSE;   
    -- Get sessionId for the provided mobile number
    SELECT SessionId INTO @sessionId FROM UserComplaintSessions WHERE Mobile = mobileNumber;
    -- Check if sessionId exists
    IF @sessionId IS NOT NULL THEN
        -- Update ComplaintStatus
        UPDATE UserComplaintSessions
        SET ComplaintStatus = complaintStatus
        	WHERE SessionId = @sessionId;
        
        -- Set sessionExists to true
        SET sessionExists = TRUE;
    END IF;
    
    -- Return true if session exists; otherwise, return false
    SELECT sessionExists;
END

DELIMITER ;