DELIMITER //

CREATE PROCEDURE UpdateUserComplaintLocation (
    IN mobileNumber VARCHAR(20), 
    IN latitude DECIMAL(10,8), 
    IN longitude DECIMAL(10,8)
)   
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 latitude, longitude, and ComplaintStatus
        UPDATE UserComplaintSessions
        	SET Latitude = latitude, Longitude = longitude
        	WHERE SessionId = @sessionId;
        
        -- Set sessionExists to true
        SET sessionExists = TRUE;
    END IF;  
    -- Return true if session exists; otherwise, return false
    SELECT sessionExists;
END

DELIMITER ;