import json


def get_team_member_id(requested_team_member: str, integration_context: dict) -> str:
    """
    Gets team member ID based on name, email or principal name
    :param requested_team_member: Team member name / principal name / email to look for
    :param integration_context: Cached object to search for team member in
    :return: Team member ID
    """
    teams: list = json.loads(integration_context.get('teams', '[]'))

    for team in teams:
        team_members: list = team.get('team_members', [])
        for team_member in team_members:
            if requested_team_member in {team_member.get('name', ''), team_member.get('userPrincipalName', '')}:
                return team_member.get('id')

    raise ValueError(f'Team member {requested_team_member} was not found')