# Path: moira_client/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/client.py
# class ResponseStructureError(Exception):
#     def __init__(self, msg, content):
#         """
# 
#         :param msg: str error message
#         :param content: dict response content
#         """
#         self.msg = msg
#         self.content = content


from ..client import InvalidJSONError
from ..client import ResponseStructureError


MAX_FETCH_LIMIT = 1000


class EventManager:
    def __init__(self, client):
        self._client = client

    def fetch_by_trigger(self, trigger, limit=MAX_FETCH_LIMIT):
        """
        Get all events by trigger
        :param trigger: Trigger trigger
        :param limit: int limit
        :return: list of dicts

        :raises: ValueError
        :raises: ResponseStructureError
        """
        if not trigger.id:
            raise ValueError('Trigger id is None')
        params = {
            'p': 0,
            'size': limit
        }
        result = self._client.get(self._full_path(trigger.id), params=params)
        if 'list' not in result:

# Path: moira_client/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/client.py
# class ResponseStructureError(Exception):
#     def __init__(self, msg, content):
#         """
# 
#         :param msg: str error message
#         :param content: dict response content
#         """
#         self.msg = msg
#         self.content = content


# Path: moira_client/models/event.py
from ..client import InvalidJSONError
from ..client import ResponseStructureError



MAX_FETCH_LIMIT = 1000


class EventManager:
    def __init__(self, client):
        self._client = client

    def fetch_by_trigger(self, trigger, limit=MAX_FETCH_LIMIT):
        """
        Get all events by trigger
        :param trigger: Trigger trigger
        :param limit: int limit
        :return: list of dicts

        :raises: ValueError
        :raises: ResponseStructureError
        """
        if not trigger.id:
            raise ValueError('Trigger id is None')
        params = {
            'p': 0,
            'size': limit
        }
        result = self._client.get(self._full_path(trigger.id), params=params)
        if 'list' not in result:

            raise ResponseStructureError("list doesn't exist in response", result)