DELIMITER //

CREATE PROCEDURE UpdateUserComplaintImage (
    IN mobileNumber VARCHAR(20), 
    IN imageUrl VARCHAR(255)
)   
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 ImageUrl and ComplaintStatus
        UPDATE UserComplaintSessions
        	SET ImageUrl = imageUrl
        WHERE SessionId = @sessionId;
        
        -- Set sessionExists to true
        SET sessionExists = TRUE;
    END IF;
    
    -- Return true if session exists; otherwise, return false
    SELECT sessionExists;
END

DELIMITER ;