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

"""
    greenbyteapi

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

from greenbyteapi.api_helper import APIHelper
import greenbyteapi.models.data_signal
import greenbyteapi.models.status_item

class StatusItem(object):

    """Implementation of the 'StatusItem' model.

    A status that may contain statuses of the same type as sub-statuses. Note
    that for sub-statuses the fields `categoryIec`, `categoryContract`, and
    `subStatus` will always be null.

    Attributes:
        turbine_status_id (int): The id of a turbine status.
        device_id (int): The id of the device affected by the status.
        timestamp_start (datetime): The timestamp when the status began. The
            timestamp is in the time zone configured in the Greenbyte Platform
            without UTC offset.
        timestamp_end (datetime): The timestamp when the status ended. The
            timestamp is in the time zone configured in the Greenbyte Platform
            without UTC offset.
        has_timestamp_end (bool): Indicates whether the status has a
            duration.
        category (StatusCategoryEnum): The category a status belongs to.
        code (float): The status code.
        message (string): A description of the status code.
        comment (string): A user comment associated with the status.
        lost_production_signal (DataSignal): A data signal.
        lost_production (float): The lost production in kWh associated with
            the status. This field will be null if the caller is not
            authorized for the system-configured lost production signal. The
            configured lost production signal is available via the
            `/configuration.json` endpoint (`DataSignalConfiguration`
            schema).
        category_iec (string): The status category as defined by the IEC.
        category_contract (string): The status category as defined in the
            availability contract assigned to the site.
        category_contract_global (string): The status category as defined in
            the global availability contract assigned to the site.
        category_contract_custom (string): The status category as defined in
            the custom availability contract assigned to the site.
        sub_status (list of StatusItem): Statuses of the same type that have
            been grouped under this status.
        acknowledged (bool): Indicates whether the status has been
            acknowledged.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "turbine_status_id":'turbineStatusId',
        "device_id":'deviceId',
        "timestamp_start":'timestampStart',
        "timestamp_end":'timestampEnd',
        "has_timestamp_end":'hasTimestampEnd',
        "category":'category',
        "code":'code',
        "message":'message',
        "comment":'comment',
        "lost_production_signal":'lostProductionSignal',
        "lost_production":'lostProduction',
        "category_iec":'categoryIec',
        "category_contract":'categoryContract',
        "category_contract_global":'categoryContractGlobal',
        "category_contract_custom":'categoryContractCustom',
        "sub_status":'subStatus',
        "acknowledged":'acknowledged'
    }

    def __init__(self,
                 turbine_status_id=None,
                 device_id=None,
                 timestamp_start=None,
                 timestamp_end=None,
                 has_timestamp_end=None,
                 category=None,
                 code=None,
                 message=None,
                 comment=None,
                 lost_production_signal=None,
                 lost_production=None,
                 category_iec=None,
                 category_contract=None,
                 category_contract_global=None,
                 category_contract_custom=None,
                 sub_status=None,
                 acknowledged=None):
        """Constructor for the StatusItem class"""

        # Initialize members of the class
        self.turbine_status_id = turbine_status_id
        self.device_id = device_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.has_timestamp_end = has_timestamp_end
        self.category = category
        self.code = code
        self.message = message
        self.comment = comment
        self.lost_production_signal = lost_production_signal
        self.lost_production = lost_production
        self.category_iec = category_iec
        self.category_contract = category_contract
        self.category_contract_global = category_contract_global
        self.category_contract_custom = category_contract_custom
        self.sub_status = sub_status
        self.acknowledged = acknowledged


    @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
        turbine_status_id = dictionary.get('turbineStatusId')
        device_id = dictionary.get('deviceId')
        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
        has_timestamp_end = dictionary.get('hasTimestampEnd')
        category = dictionary.get('category')
        code = dictionary.get('code')
        message = dictionary.get('message')
        comment = dictionary.get('comment')
        lost_production_signal = greenbyteapi.models.data_signal.DataSignal.from_dictionary(dictionary.get('lostProductionSignal')) if dictionary.get('lostProductionSignal') else None
        lost_production = dictionary.get('lostProduction')
        category_iec = dictionary.get('categoryIec')
        category_contract = dictionary.get('categoryContract')
        category_contract_global = dictionary.get('categoryContractGlobal')
        category_contract_custom = dictionary.get('categoryContractCustom')
        sub_status = None
        if dictionary.get('subStatus') != None:
            sub_status = list()
            for structure in dictionary.get('subStatus'):
                sub_status.append(greenbyteapi.models.status_item.StatusItem.from_dictionary(structure))
        acknowledged = dictionary.get('acknowledged')

        # Return an object of this model
        return cls(turbine_status_id,
                   device_id,
                   timestamp_start,
                   timestamp_end,
                   has_timestamp_end,
                   category,
                   code,
                   message,
                   comment,
                   lost_production_signal,
                   lost_production,
                   category_iec,
                   category_contract,
                   category_contract_global,
                   category_contract_custom,
                   sub_status,
                   acknowledged)


