# -*- 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.artist_object import ArtistObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.external_id_object import ExternalIdObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.external_url_object import ExternalUrlObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.linked_track_object import LinkedTrackObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.simplified_album_object import SimplifiedAlbumObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.track_restriction_object import TrackRestrictionObject


class TrackObject(object):

    """Implementation of the 'TrackObject' model.

    Attributes:
        album (SimplifiedAlbumObject): The album on which the track appears.
            The album object includes a link in `href` to full information
            about the album.
        artists (List[ArtistObject]): The artists who performed the track.
            Each artist object includes a link in `href` to more detailed
            information about the artist.
        available_markets (List[str]): A list of the countries in which the
            track can be played, identified by their [ISO 3166-1
            alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
        disc_number (int): The disc number (usually `1` unless the album
            consists of more than one disc).
        duration_ms (int): The track length in milliseconds.
        explicit (bool): Whether or not the track has explicit lyrics ( `true`
            = yes it does; `false` = no it does not OR unknown).
        external_ids (ExternalIdObject): Known external IDs for the track.
        external_urls (ExternalUrlObject): Known external URLs for this track.
        href (str): A link to the Web API endpoint providing full details of
            the track.
        id (str): The [Spotify
            ID](/documentation/web-api/concepts/spotify-uris-ids) for the
            track.
        is_playable (bool): Part of the response when [Track
            Relinking](/documentation/web-api/concepts/track-relinking) is
            applied. If `true`, the track is playable in the given market.
            Otherwise `false`.
        linked_from (LinkedTrackObject): Part of the response when [Track
            Relinking](/documentation/web-api/concepts/track-relinking) is
            applied, and the requested track has been replaced with different
            track. The track in the `linked_from` object contains information
            about the originally requested track.
        restrictions (TrackRestrictionObject): Included in the response when a
            content restriction is applied.
        name (str): The name of the track.
        popularity (int): The popularity of the track. The value will be
            between 0 and 100, with 100 being the most popular.<br/>The
            popularity of a track is a value between 0 and 100, with 100 being
            the most popular. The popularity is calculated by algorithm and is
            based, in the most part, on the total number of plays the track
            has had and how recent those plays are.<br/>Generally speaking,
            songs that are being played a lot now will have a higher
            popularity than songs that were played a lot in the past.
            Duplicate tracks (e.g. the same track from a single and an album)
            are rated independently. Artist and album popularity is derived
            mathematically from track popularity. _**Note**: the popularity
            value may lag actual popularity by a few days: the value is not
            updated in real time._
        preview_url (str): A link to a 30 second preview (MP3 format) of the
            track. Can be `null`
        track_number (int): The number of the track. If an album has several
            discs, the track number is the number on the specified disc.
        mtype (Type2Enum): The object type: "track".
        uri (str): The [Spotify
            URI](/documentation/web-api/concepts/spotify-uris-ids) for the
            track.
        is_local (bool): Whether or not the track is from a local file.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "album": 'album',
        "artists": 'artists',
        "available_markets": 'available_markets',
        "disc_number": 'disc_number',
        "duration_ms": 'duration_ms',
        "explicit": 'explicit',
        "external_ids": 'external_ids',
        "external_urls": 'external_urls',
        "href": 'href',
        "id": 'id',
        "is_playable": 'is_playable',
        "linked_from": 'linked_from',
        "restrictions": 'restrictions',
        "name": 'name',
        "popularity": 'popularity',
        "preview_url": 'preview_url',
        "track_number": 'track_number',
        "mtype": 'type',
        "uri": 'uri',
        "is_local": 'is_local'
    }

    _optionals = [
        'album',
        'artists',
        'available_markets',
        'disc_number',
        'duration_ms',
        'explicit',
        'external_ids',
        'external_urls',
        'href',
        'id',
        'is_playable',
        'linked_from',
        'restrictions',
        'name',
        'popularity',
        'preview_url',
        'track_number',
        'mtype',
        'uri',
        'is_local',
    ]

    _nullables = [
        'preview_url',
    ]

    def __init__(self,
                 album=APIHelper.SKIP,
                 artists=APIHelper.SKIP,
                 available_markets=APIHelper.SKIP,
                 disc_number=APIHelper.SKIP,
                 duration_ms=APIHelper.SKIP,
                 explicit=APIHelper.SKIP,
                 external_ids=APIHelper.SKIP,
                 external_urls=APIHelper.SKIP,
                 href=APIHelper.SKIP,
                 id=APIHelper.SKIP,
                 is_playable=APIHelper.SKIP,
                 linked_from=APIHelper.SKIP,
                 restrictions=APIHelper.SKIP,
                 name=APIHelper.SKIP,
                 popularity=APIHelper.SKIP,
                 preview_url=APIHelper.SKIP,
                 track_number=APIHelper.SKIP,
                 mtype=APIHelper.SKIP,
                 uri=APIHelper.SKIP,
                 is_local=APIHelper.SKIP):
        """Constructor for the TrackObject class"""

        # Initialize members of the class
        if album is not APIHelper.SKIP:
            self.album = album 
        if artists is not APIHelper.SKIP:
            self.artists = artists 
        if available_markets is not APIHelper.SKIP:
            self.available_markets = available_markets 
        if disc_number is not APIHelper.SKIP:
            self.disc_number = disc_number 
        if duration_ms is not APIHelper.SKIP:
            self.duration_ms = duration_ms 
        if explicit is not APIHelper.SKIP:
            self.explicit = explicit 
        if external_ids is not APIHelper.SKIP:
            self.external_ids = external_ids 
        if external_urls is not APIHelper.SKIP:
            self.external_urls = external_urls 
        if href is not APIHelper.SKIP:
            self.href = href 
        if id is not APIHelper.SKIP:
            self.id = id 
        if is_playable is not APIHelper.SKIP:
            self.is_playable = is_playable 
        if linked_from is not APIHelper.SKIP:
            self.linked_from = linked_from 
        if restrictions is not APIHelper.SKIP:
            self.restrictions = restrictions 
        if name is not APIHelper.SKIP:
            self.name = name 
        if popularity is not APIHelper.SKIP:
            self.popularity = popularity 
        if preview_url is not APIHelper.SKIP:
            self.preview_url = preview_url 
        if track_number is not APIHelper.SKIP:
            self.track_number = track_number 
        if mtype is not APIHelper.SKIP:
            self.mtype = mtype 
        if uri is not APIHelper.SKIP:
            self.uri = uri 
        if is_local is not APIHelper.SKIP:
            self.is_local = is_local 

    @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
        album = SimplifiedAlbumObject.from_dictionary(dictionary.get('album')) if 'album' in dictionary.keys() else APIHelper.SKIP
        artists = None
        if dictionary.get('artists') is not None:
            artists = [ArtistObject.from_dictionary(x) for x in dictionary.get('artists')]
        else:
            artists = APIHelper.SKIP
        available_markets = dictionary.get("available_markets") if dictionary.get("available_markets") else APIHelper.SKIP
        disc_number = dictionary.get("disc_number") if dictionary.get("disc_number") else APIHelper.SKIP
        duration_ms = dictionary.get("duration_ms") if dictionary.get("duration_ms") else APIHelper.SKIP
        explicit = dictionary.get("explicit") if "explicit" in dictionary.keys() else APIHelper.SKIP
        external_ids = ExternalIdObject.from_dictionary(dictionary.get('external_ids')) if 'external_ids' in dictionary.keys() else APIHelper.SKIP
        external_urls = ExternalUrlObject.from_dictionary(dictionary.get('external_urls')) if 'external_urls' in dictionary.keys() else APIHelper.SKIP
        href = dictionary.get("href") if dictionary.get("href") else APIHelper.SKIP
        id = dictionary.get("id") if dictionary.get("id") else APIHelper.SKIP
        is_playable = dictionary.get("is_playable") if "is_playable" in dictionary.keys() else APIHelper.SKIP
        linked_from = LinkedTrackObject.from_dictionary(dictionary.get('linked_from')) if 'linked_from' in dictionary.keys() else APIHelper.SKIP
        restrictions = TrackRestrictionObject.from_dictionary(dictionary.get('restrictions')) if 'restrictions' in dictionary.keys() else APIHelper.SKIP
        name = dictionary.get("name") if dictionary.get("name") else APIHelper.SKIP
        popularity = dictionary.get("popularity") if dictionary.get("popularity") else APIHelper.SKIP
        preview_url = dictionary.get("preview_url") if "preview_url" in dictionary.keys() else APIHelper.SKIP
        track_number = dictionary.get("track_number") if dictionary.get("track_number") else APIHelper.SKIP
        mtype = dictionary.get("type") if dictionary.get("type") else APIHelper.SKIP
        uri = dictionary.get("uri") if dictionary.get("uri") else APIHelper.SKIP
        is_local = dictionary.get("is_local") if "is_local" in dictionary.keys() else APIHelper.SKIP
        # Return an object of this model
        return cls(album,
                   artists,
                   available_markets,
                   disc_number,
                   duration_ms,
                   explicit,
                   external_ids,
                   external_urls,
                   href,
                   id,
                   is_playable,
                   linked_from,
                   restrictions,
                   name,
                   popularity,
                   preview_url,
                   track_number,
                   mtype,
                   uri,
                   is_local)

    @classmethod
    def validate(cls, dictionary):
        """Validates dictionary against class required properties

        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:
            boolean : if dictionary is valid contains required properties.

        """

        if isinstance(dictionary, cls):
            return True

        if not isinstance(dictionary, dict):
            return False

        return True

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'album={(self.album if hasattr(self, "album") else None)!r}, '
                f'artists={(self.artists if hasattr(self, "artists") else None)!r}, '
                f'available_markets={(self.available_markets if hasattr(self, "available_markets") else None)!r}, '
                f'disc_number={(self.disc_number if hasattr(self, "disc_number") else None)!r}, '
                f'duration_ms={(self.duration_ms if hasattr(self, "duration_ms") else None)!r}, '
                f'explicit={(self.explicit if hasattr(self, "explicit") else None)!r}, '
                f'external_ids={(self.external_ids if hasattr(self, "external_ids") else None)!r}, '
                f'external_urls={(self.external_urls if hasattr(self, "external_urls") else None)!r}, '
                f'href={(self.href if hasattr(self, "href") else None)!r}, '
                f'id={(self.id if hasattr(self, "id") else None)!r}, '
                f'is_playable={(self.is_playable if hasattr(self, "is_playable") else None)!r}, '
                f'linked_from={(self.linked_from if hasattr(self, "linked_from") else None)!r}, '
                f'restrictions={(self.restrictions if hasattr(self, "restrictions") else None)!r}, '
                f'name={(self.name if hasattr(self, "name") else None)!r}, '
                f'popularity={(self.popularity if hasattr(self, "popularity") else None)!r}, '
                f'preview_url={(self.preview_url if hasattr(self, "preview_url") else None)!r}, '
                f'track_number={(self.track_number if hasattr(self, "track_number") else None)!r}, '
                f'mtype={(self.mtype if hasattr(self, "mtype") else None)!r}, '
                f'uri={(self.uri if hasattr(self, "uri") else None)!r}, '
                f'is_local={(self.is_local if hasattr(self, "is_local") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'album={(self.album if hasattr(self, "album") else None)!s}, '
                f'artists={(self.artists if hasattr(self, "artists") else None)!s}, '
                f'available_markets={(self.available_markets if hasattr(self, "available_markets") else None)!s}, '
                f'disc_number={(self.disc_number if hasattr(self, "disc_number") else None)!s}, '
                f'duration_ms={(self.duration_ms if hasattr(self, "duration_ms") else None)!s}, '
                f'explicit={(self.explicit if hasattr(self, "explicit") else None)!s}, '
                f'external_ids={(self.external_ids if hasattr(self, "external_ids") else None)!s}, '
                f'external_urls={(self.external_urls if hasattr(self, "external_urls") else None)!s}, '
                f'href={(self.href if hasattr(self, "href") else None)!s}, '
                f'id={(self.id if hasattr(self, "id") else None)!s}, '
                f'is_playable={(self.is_playable if hasattr(self, "is_playable") else None)!s}, '
                f'linked_from={(self.linked_from if hasattr(self, "linked_from") else None)!s}, '
                f'restrictions={(self.restrictions if hasattr(self, "restrictions") else None)!s}, '
                f'name={(self.name if hasattr(self, "name") else None)!s}, '
                f'popularity={(self.popularity if hasattr(self, "popularity") else None)!s}, '
                f'preview_url={(self.preview_url if hasattr(self, "preview_url") else None)!s}, '
                f'track_number={(self.track_number if hasattr(self, "track_number") else None)!s}, '
                f'mtype={(self.mtype if hasattr(self, "mtype") else None)!s}, '
                f'uri={(self.uri if hasattr(self, "uri") else None)!s}, '
                f'is_local={(self.is_local if hasattr(self, "is_local") else None)!s})')
