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

"""
    greenbyteapi

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

import greenbyteapi.models.data_signal

class DataItem(object):

    """Implementation of the 'DataItem' model.

    An object containing time-series data for a specific aggregate, data
    signal and interval.

    Attributes:
        aggregate (AggregateModeEnum): How data is aggregated in the asset
            structure.
        aggregate_id (int): The id of this aggregate group: device id, site
            id, or the constant -1 for portfolio. For `siteLevel` aggregation
            a generated unique id is used.
        aggregate_path_names (list of string): For `siteLevel` aggregation
            this contains the title for each level in the hierarchy. For other
            types of aggregation it will be empty.
        device_ids (list of int): The ids of the devices in this aggregate
            group.
        resolution (ResolutionEnum): The resolution of the data. Note: For
            requests with *device* as the specified resolution, the actual
            resolution will be returned e.g. *10minute*.
        calculation (CalculationModeEnum): Which operation to use when
            aggregating data.
        data_signal (DataSignal): A data signal.
        data (dict<object, float>): A dictionary with timestamp as key and the
            data measurement as value. The timestamp is in the time zone
            configured in the Greenbyte Platform without UTC offset. Example:
            `{ ..., "2020-01-01T00:00:00": 584.33, ... }`.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "aggregate":'aggregate',
        "aggregate_id":'aggregateId',
        "device_ids":'deviceIds',
        "resolution":'resolution',
        "calculation":'calculation',
        "data_signal":'dataSignal',
        "data":'data',
        "aggregate_path_names":'aggregatePathNames'
    }

    def __init__(self,
                 aggregate='device',
                 aggregate_id=None,
                 device_ids=None,
                 resolution=None,
                 calculation=None,
                 data_signal=None,
                 data=None,
                 aggregate_path_names=None):
        """Constructor for the DataItem class"""

        # Initialize members of the class
        self.aggregate = aggregate
        self.aggregate_id = aggregate_id
        self.aggregate_path_names = aggregate_path_names
        self.device_ids = device_ids
        self.resolution = resolution
        self.calculation = calculation
        self.data_signal = data_signal
        self.data = data


    @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
        aggregate = dictionary.get("aggregate") if dictionary.get("aggregate") else 'device'
        aggregate_id = dictionary.get('aggregateId')
        device_ids = dictionary.get('deviceIds')
        resolution = dictionary.get('resolution')
        calculation = dictionary.get('calculation')
        data_signal = greenbyteapi.models.data_signal.DataSignal.from_dictionary(dictionary.get('dataSignal')) if dictionary.get('dataSignal') else None
        data = dictionary.get('data')
        aggregate_path_names = dictionary.get('aggregatePathNames')

        # Return an object of this model
        return cls(aggregate,
                   aggregate_id,
                   device_ids,
                   resolution,
                   calculation,
                   data_signal,
                   data,
                   aggregate_path_names)


