# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return


from datetime import datetime
from alertaclient.utils import DateTime



class Note:

    def __init__(self, text, user, note_type, **kwargs):

        self.id = kwargs.get('id', None)
        self.text = text
        self.user = user
        self.note_type = note_type
        self.attributes = kwargs.get('attributes', None) or dict()
        self.create_time = kwargs['create_time'] if 'create_time' in kwargs else datetime.utcnow()
        self.update_time = kwargs.get('update_time')
        self.alert = kwargs.get('alert')
        self.customer = kwargs.get('customer')

    @classmethod
    def parse(cls, json):
        return Note(
            id=json.get('id', None),
            text=json.get('text', None),
            user=json.get('user', None),
            attributes=json.get('attributes', dict()),
            note_type=json.get('type', None),
            create_time=DateTime.parse(json['createTime']) if 'createTime' in json else None,

# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return


# Path: alertaclient/models/note.py
from datetime import datetime
from alertaclient.utils import DateTime




class Note:

    def __init__(self, text, user, note_type, **kwargs):

        self.id = kwargs.get('id', None)
        self.text = text
        self.user = user
        self.note_type = note_type
        self.attributes = kwargs.get('attributes', None) or dict()
        self.create_time = kwargs['create_time'] if 'create_time' in kwargs else datetime.utcnow()
        self.update_time = kwargs.get('update_time')
        self.alert = kwargs.get('alert')
        self.customer = kwargs.get('customer')

    @classmethod
    def parse(cls, json):
        return Note(
            id=json.get('id', None),
            text=json.get('text', None),
            user=json.get('user', None),
            attributes=json.get('attributes', dict()),
            note_type=json.get('type', None),
            create_time=DateTime.parse(json['createTime']) if 'createTime' in json else None,

            update_time=DateTime.parse(json['updateTime']) if 'updateTime' in json else None,