# 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/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/models/base.py
# class Base:
#     @property
#     def id(self):
#         return self._id
# 
#     def __repr__(self):
#         return '({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __unicode__(self):
#         return u'({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __eq__(self, other):
#         return self.id == other.id
# 
#     def __ne__(self, other):
#         return self.id != other.id
# 
# Path: moira_client/models/common.py
# MINUTES_IN_HOUR = 60
# 
# def get_schedule(start_hour, start_minute, end_hour, end_minute, disabled_days):
#     days = []
#     for day in DAYS_OF_WEEK:
#         day_info = {
#             'enabled': True if day not in disabled_days else False,
#             'name': day
#         }
#         days.append(day_info)
#     return {
#         'days': days,
#         'startOffset': start_hour * MINUTES_IN_HOUR + start_minute,
#         'endOffset': end_hour * MINUTES_IN_HOUR + end_minute,
#     }


from ..client import ResponseStructureError
from ..client import InvalidJSONError
from .base import Base
from .common import MINUTES_IN_HOUR, get_schedule

    def check_exists(self):
        """
        Check if current trigger exists

        :return: trigger id if exists, None otherwise
        """
        trigger_manager = TriggerManager(self._client)
        for trigger in trigger_manager.fetch_all():
            if self.name == trigger.name and \
                set(self.targets) == set(trigger.targets) and \
                    set(self.tags) == set(trigger.tags):
                return trigger

    def get_metrics(self, start, end):
        """
        Get metrics associated with certain trigger

        :param start: The start period of metrics to get. Example : -1hour
        :param end: The end period of metrics to get. Example : now

        :return: Metrics for trigger
        """
        try:
            params = {
                'from': start,
                'to': end,
            }
            result = self._client.get('trigger/{id}/metrics'.format(id=self.id), params=params)
            return result

# 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/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/models/base.py
# class Base:
#     @property
#     def id(self):
#         return self._id
# 
#     def __repr__(self):
#         return '({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __unicode__(self):
#         return u'({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __eq__(self, other):
#         return self.id == other.id
# 
#     def __ne__(self, other):
#         return self.id != other.id
# 
# Path: moira_client/models/common.py
# MINUTES_IN_HOUR = 60
# 
# def get_schedule(start_hour, start_minute, end_hour, end_minute, disabled_days):
#     days = []
#     for day in DAYS_OF_WEEK:
#         day_info = {
#             'enabled': True if day not in disabled_days else False,
#             'name': day
#         }
#         days.append(day_info)
#     return {
#         'days': days,
#         'startOffset': start_hour * MINUTES_IN_HOUR + start_minute,
#         'endOffset': end_hour * MINUTES_IN_HOUR + end_minute,
#     }


# Path: moira_client/models/trigger.py
from ..client import ResponseStructureError
from ..client import InvalidJSONError
from .base import Base
from .common import MINUTES_IN_HOUR, get_schedule


    def check_exists(self):
        """
        Check if current trigger exists

        :return: trigger id if exists, None otherwise
        """
        trigger_manager = TriggerManager(self._client)
        for trigger in trigger_manager.fetch_all():
            if self.name == trigger.name and \
                set(self.targets) == set(trigger.targets) and \
                    set(self.tags) == set(trigger.tags):
                return trigger

    def get_metrics(self, start, end):
        """
        Get metrics associated with certain trigger

        :param start: The start period of metrics to get. Example : -1hour
        :param end: The end period of metrics to get. Example : now

        :return: Metrics for trigger
        """
        try:
            params = {
                'from': start,
                'to': end,
            }
            result = self._client.get('trigger/{id}/metrics'.format(id=self.id), params=params)
            return result

        except InvalidJSONError: