# -*- 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.configuration import Server
from spotifywebapiwithfixesandimprovementsfromsonallux.controllers.base_controller import BaseController
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from spotifywebapiwithfixesandimprovementsfromsonallux.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from spotifywebapiwithfixesandimprovementsfromsonallux.models.artist_object import ArtistObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.many_artists import ManyArtists
from spotifywebapiwithfixesandimprovementsfromsonallux.models.paging_artist_discography_album_object import PagingArtistDiscographyAlbumObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.many_tracks import ManyTracks
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.unauthorized_exception import UnauthorizedException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.forbidden_exception import ForbiddenException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.too_many_requests_exception import TooManyRequestsException


class ArtistsController(BaseController):

    """A Controller to access Endpoints in the spotifywebapiwithfixesandimprovementsfromsonallux API."""
    def __init__(self, config):
        super(ArtistsController, self).__init__(config)

    def get_an_artist(self,
                      id):
        """Does a GET request to /artists/{id}.

        Get Spotify catalog information for a single artist identified by
        their unique Spotify ID.

        Args:
            id (str): The request template parameter.

        Returns:
            ArtistObject: Response from the API. An artist

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/artists/{id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('oauth_2_0'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ArtistObject.from_dictionary)
            .local_error('401', 'Bad or expired token. This can happen if the user revoked a token or\nthe access token has expired. You should re-authenticate the user.\n', UnauthorizedException)
            .local_error('403', 'Bad OAuth request (wrong consumer key, bad nonce, expired\ntimestamp...). Unfortunately, re-authenticating the user won\'t help here.\n', ForbiddenException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()

    def get_multiple_artists(self,
                             ids):
        """Does a GET request to /artists.

        Get Spotify catalog information for several artists based on their
        Spotify IDs.

        Args:
            ids (str): The request query parameter.

        Returns:
            ManyArtists: Response from the API. A set of artists

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/artists')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('ids')
                         .value(ids))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('oauth_2_0'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ManyArtists.from_dictionary)
            .local_error('401', 'Bad or expired token. This can happen if the user revoked a token or\nthe access token has expired. You should re-authenticate the user.\n', UnauthorizedException)
            .local_error('403', 'Bad OAuth request (wrong consumer key, bad nonce, expired\ntimestamp...). Unfortunately, re-authenticating the user won\'t help here.\n', ForbiddenException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()

    def get_an_artists_albums(self,
                              id,
                              include_groups=None,
                              market=None,
                              limit=20,
                              offset=0):
        """Does a GET request to /artists/{id}/albums.

        Get Spotify catalog information about an artist's albums.

        Args:
            id (str): The request template parameter.
            include_groups (str, optional): The request query parameter.
            market (str, optional): The request query parameter.
            limit (int, optional): The request query parameter. Example: 20
            offset (int, optional): The request query parameter. Example: 0

        Returns:
            PagingArtistDiscographyAlbumObject: Response from the API. Pages
                of albums

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/artists/{id}/albums')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('include_groups')
                         .value(include_groups))
            .query_param(Parameter()
                         .key('market')
                         .value(market))
            .query_param(Parameter()
                         .key('limit')
                         .value(limit))
            .query_param(Parameter()
                         .key('offset')
                         .value(offset))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('oauth_2_0'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PagingArtistDiscographyAlbumObject.from_dictionary)
            .local_error('401', 'Bad or expired token. This can happen if the user revoked a token or\nthe access token has expired. You should re-authenticate the user.\n', UnauthorizedException)
            .local_error('403', 'Bad OAuth request (wrong consumer key, bad nonce, expired\ntimestamp...). Unfortunately, re-authenticating the user won\'t help here.\n', ForbiddenException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()

    def get_an_artists_top_tracks(self,
                                  id,
                                  market=None):
        """Does a GET request to /artists/{id}/top-tracks.

        Get Spotify catalog information about an artist's top tracks by
        country.

        Args:
            id (str): The request template parameter.
            market (str, optional): The request query parameter.

        Returns:
            ManyTracks: Response from the API. A set of tracks

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/artists/{id}/top-tracks')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('market')
                         .value(market))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('oauth_2_0'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ManyTracks.from_dictionary)
            .local_error('401', 'Bad or expired token. This can happen if the user revoked a token or\nthe access token has expired. You should re-authenticate the user.\n', UnauthorizedException)
            .local_error('403', 'Bad OAuth request (wrong consumer key, bad nonce, expired\ntimestamp...). Unfortunately, re-authenticating the user won\'t help here.\n', ForbiddenException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()

    def get_an_artists_related_artists(self,
                                       id):
        """Does a GET request to /artists/{id}/related-artists.

        Get Spotify catalog information about artists similar to a given
        artist. Similarity is based on analysis of the Spotify community's
        listening history.

        Args:
            id (str): The request template parameter.

        Returns:
            ManyArtists: Response from the API. A set of artists

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/artists/{id}/related-artists')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('oauth_2_0'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ManyArtists.from_dictionary)
            .local_error('401', 'Bad or expired token. This can happen if the user revoked a token or\nthe access token has expired. You should re-authenticate the user.\n', UnauthorizedException)
            .local_error('403', 'Bad OAuth request (wrong consumer key, bad nonce, expired\ntimestamp...). Unfortunately, re-authenticating the user won\'t help here.\n', ForbiddenException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()
