class ToonSchema:

    def __init__(self, schema):

        self.schema = schema


    def _validate(self, obj, schema):

        for key, expected in schema.items():

            if key not in obj:
                raise ValueError(f"Missing field: {key}")

            value = obj[key]

            if isinstance(expected, dict):

                if not isinstance(value, dict):
                    raise TypeError(f"{key} must be object")

                self._validate(value, expected)

            elif expected == list:

                if not isinstance(value, list):
                    raise TypeError(f"{key} must be list")

            else:

                if not isinstance(value, expected):
                    raise TypeError(
                        f"{key} expected {expected}, got {type(value)}"
                    )


    def validate(self, items):

        for obj in items:
            self._validate(obj, self.schema)

        return True