# Path: socceraction/data/base.py
# class MissingDataError(Exception):
#     """Exception raised when a field is missing in the input data."""
# 
# Path: socceraction/data/opta/parsers/base.py
# class OptaJSONParser(OptaParser):
#     """Extract data from an Opta JSON data stream.
# 
#     Parameters
#     ----------
#     path : str
#         Path of the data file.
#     """
# 
#     def __init__(self, path: str, **kwargs: Any) -> None:
#         with open(path, 'rt', encoding='utf-8') as fh:
#             self.root = json.load(fh)
# 
# def assertget(dictionary: Dict[str, Any], key: str) -> Any:
#     """Return the value of the item with the specified key.
# 
#     In contrast to the default `get` method, this version will raise an
#     assertion error if the given key is not present in the dict.
# 
#     Parameters
#     ----------
#     dictionary : dict
#         A Python dictionary.
#     key : str
#         A key in the dictionary.
# 
#     Returns
#     -------
#     Any
#         Returns the value for the specified key if the key is in the dictionary.
# 
#     Raises
#     ------
#     AssertionError
#         If the given key could not be found in the dictionary.
#     """
#     value = dictionary.get(key)
#     assert value is not None, 'KeyError: ' + key + ' not found in ' + str(dictionary)
#     return value


from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from ...base import MissingDataError
from .base import OptaJSONParser, assertget
        if 'matchInfo' in self.root:
            return [self.root]
        if 'match' in self.root:
            return self.root['match']
        raise MissingDataError

    def _get_match_info(self, match: Dict[str, Any]) -> Dict[str, Any]:
        if 'matchInfo' in match:
            return match['matchInfo']
        raise MissingDataError

    def _get_live_data(self, match: Dict[str, Any]) -> Dict[str, Any]:
        if 'liveData' in match:
            return match['liveData']
        return {}

    def _get_name(self, obj: Dict[str, Any]) -> Optional[str]:
        if "name" in obj:
            return assertget(obj, "name")
        if "firstName" in obj:
            return f"{assertget(obj, 'firstName')} {assertget(obj, 'lastName')}"
        return None

    @staticmethod
    def _extract_team_id(teams: List[Dict[str, str]], side: str) -> Optional[str]:
        for team in teams:
            team_side = assertget(team, "position")
            if team_side == side:
                team_id = assertget(team, "id")
                return team_id

# Path: socceraction/data/base.py
# class MissingDataError(Exception):
#     """Exception raised when a field is missing in the input data."""
# 
# Path: socceraction/data/opta/parsers/base.py
# class OptaJSONParser(OptaParser):
#     """Extract data from an Opta JSON data stream.
# 
#     Parameters
#     ----------
#     path : str
#         Path of the data file.
#     """
# 
#     def __init__(self, path: str, **kwargs: Any) -> None:
#         with open(path, 'rt', encoding='utf-8') as fh:
#             self.root = json.load(fh)
# 
# def assertget(dictionary: Dict[str, Any], key: str) -> Any:
#     """Return the value of the item with the specified key.
# 
#     In contrast to the default `get` method, this version will raise an
#     assertion error if the given key is not present in the dict.
# 
#     Parameters
#     ----------
#     dictionary : dict
#         A Python dictionary.
#     key : str
#         A key in the dictionary.
# 
#     Returns
#     -------
#     Any
#         Returns the value for the specified key if the key is in the dictionary.
# 
#     Raises
#     ------
#     AssertionError
#         If the given key could not be found in the dictionary.
#     """
#     value = dictionary.get(key)
#     assert value is not None, 'KeyError: ' + key + ' not found in ' + str(dictionary)
#     return value


# Path: socceraction/data/opta/parsers/ma1_json.py
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from ...base import MissingDataError
from .base import OptaJSONParser, assertget

        if 'matchInfo' in self.root:
            return [self.root]
        if 'match' in self.root:
            return self.root['match']
        raise MissingDataError

    def _get_match_info(self, match: Dict[str, Any]) -> Dict[str, Any]:
        if 'matchInfo' in match:
            return match['matchInfo']
        raise MissingDataError

    def _get_live_data(self, match: Dict[str, Any]) -> Dict[str, Any]:
        if 'liveData' in match:
            return match['liveData']
        return {}

    def _get_name(self, obj: Dict[str, Any]) -> Optional[str]:
        if "name" in obj:
            return assertget(obj, "name")
        if "firstName" in obj:
            return f"{assertget(obj, 'firstName')} {assertget(obj, 'lastName')}"
        return None

    @staticmethod
    def _extract_team_id(teams: List[Dict[str, str]], side: str) -> Optional[str]:
        for team in teams:
            team_side = assertget(team, "position")
            if team_side == side:
                team_id = assertget(team, "id")
                return team_id

        raise MissingDataError