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

"""
spotifywebapiwithfixesandimprovementsfromsonallux

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
from spotifywebapiwithfixesandimprovementsfromsonallux.api_helper import APIHelper
from spotifywebapiwithfixesandimprovementsfromsonallux.models.context_object import ContextObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.track_object import TrackObject


class PlayHistoryObject(object):

    """Implementation of the 'PlayHistoryObject' model.

    Attributes:
        track (TrackObject): The track the user listened to.
        played_at (datetime): The date and time the track was played.
        context (ContextObject): The context the track was played from.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "track": 'track',
        "played_at": 'played_at',
        "context": 'context'
    }

    _optionals = [
        'track',
        'played_at',
        'context',
    ]

    def __init__(self,
                 track=APIHelper.SKIP,
                 played_at=APIHelper.SKIP,
                 context=APIHelper.SKIP):
        """Constructor for the PlayHistoryObject class"""

        # Initialize members of the class
        if track is not APIHelper.SKIP:
            self.track = track 
        if played_at is not APIHelper.SKIP:
            self.played_at = APIHelper.apply_datetime_converter(played_at, APIHelper.RFC3339DateTime) if played_at else None 
        if context is not APIHelper.SKIP:
            self.context = context 

    @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 not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        track = TrackObject.from_dictionary(dictionary.get('track')) if 'track' in dictionary.keys() else APIHelper.SKIP
        played_at = APIHelper.RFC3339DateTime.from_value(dictionary.get("played_at")).datetime if dictionary.get("played_at") else APIHelper.SKIP
        context = ContextObject.from_dictionary(dictionary.get('context')) if 'context' in dictionary.keys() else APIHelper.SKIP
        # Return an object of this model
        return cls(track,
                   played_at,
                   context)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'track={(self.track if hasattr(self, "track") else None)!r}, '
                f'played_at={(self.played_at if hasattr(self, "played_at") else None)!r}, '
                f'context={(self.context if hasattr(self, "context") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'track={(self.track if hasattr(self, "track") else None)!s}, '
                f'played_at={(self.played_at if hasattr(self, "played_at") else None)!s}, '
                f'context={(self.context if hasattr(self, "context") else None)!s})')
