# -*- coding: utf-8 -*-

"""
    greenbyteapi

    This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""

from greenbyteapi.api_helper import APIHelper

class AlertItem(object):

    """Implementation of the 'AlertItem' model.

    An alert generated for a device based on a rule.

    Attributes:
        device_id (int): The id of the device the alert was generated for.
        rule_id (int): The id of the rule the alert is based on.
        timestamp_start (datetime): The timestamp when the alert began. The
            timestamp is in the time zone configured in the Greenbyte Platform
            without UTC offset.
        timestamp_end (datetime): The timestamp when the alert ended. The
            timestamp is in the time zone configured in the Greenbyte Platform
            without UTC offset.
        message (string): The title of the rule the alert is based on.
        comment (string): A user comment associated with the alert.
        description (string): A description explaning the rule the alert is
            based on.
        details (string): Additional details for the alert. Note that the
            structure of this data is subject to change.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "device_id":'deviceId',
        "rule_id":'ruleId',
        "timestamp_start":'timestampStart',
        "timestamp_end":'timestampEnd',
        "message":'message',
        "comment":'comment',
        "description":'description',
        "details":'details'
    }

    def __init__(self,
                 device_id=None,
                 rule_id=None,
                 timestamp_start=None,
                 timestamp_end=None,
                 message=None,
                 comment=None,
                 description=None,
                 details=None):
        """Constructor for the AlertItem class"""

        # Initialize members of the class
        self.device_id = device_id
        self.rule_id = rule_id
        self.timestamp_start = APIHelper.RFC3339DateTime(timestamp_start) if timestamp_start else None
        self.timestamp_end = APIHelper.RFC3339DateTime(timestamp_end) if timestamp_end else None
        self.message = message
        self.comment = comment
        self.description = description
        self.details = details


    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Creates an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object as
            obtained from the deserialization of the server's response. The keys
            MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if dictionary is None:
            return None

        # Extract variables from the dictionary
        device_id = dictionary.get('deviceId')
        rule_id = dictionary.get('ruleId')
        timestamp_start = APIHelper.RFC3339DateTime.from_value(dictionary.get("timestampStart")).datetime if dictionary.get("timestampStart") else None
        timestamp_end = APIHelper.RFC3339DateTime.from_value(dictionary.get("timestampEnd")).datetime if dictionary.get("timestampEnd") else None
        message = dictionary.get('message')
        comment = dictionary.get('comment')
        description = dictionary.get('description')
        details = dictionary.get('details')

        # Return an object of this model
        return cls(device_id,
                   rule_id,
                   timestamp_start,
                   timestamp_end,
                   message,
                   comment,
                   description,
                   details)


