# -*- 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.audiobook_object import AudiobookObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.many_audiobooks import ManyAudiobooks
from spotifywebapiwithfixesandimprovementsfromsonallux.models.paging_simplified_chapter_object import PagingSimplifiedChapterObject
from spotifywebapiwithfixesandimprovementsfromsonallux.models.paging_saved_audiobook_object import PagingSavedAudiobookObject
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.bad_request_exception import BadRequestException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.unauthorized_exception import UnauthorizedException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.forbidden_exception import ForbiddenException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.not_found_exception import NotFoundException
from spotifywebapiwithfixesandimprovementsfromsonallux.exceptions.too_many_requests_exception import TooManyRequestsException


class AudiobooksController(BaseController):

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

    def get_an_audiobook(self,
                         id,
                         market=None):
        """Does a GET request to /audiobooks/{id}.

        Get Spotify catalog information for a single audiobook. Audiobooks are
        only available within the US, UK, Canada, Ireland, New Zealand and
        Australia markets.

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

        Returns:
            AudiobookObject: Response from the API. An Audiobook

        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('/audiobooks/{id}')
            .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(AudiobookObject.from_dictionary)
            .local_error('400', 'The request contains malformed data in path, query parameters, or body.\n', BadRequestException)
            .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('404', 'The requested resource cannot be found.\n', NotFoundException)
            .local_error('429', 'The app has exceeded its rate limits.\n', TooManyRequestsException)
        ).execute()

    def get_multiple_audiobooks(self,
                                ids,
                                market=None):
        """Does a GET request to /audiobooks.

        Get Spotify catalog information for several audiobooks identified by
        their Spotify IDs. Audiobooks are only available within the US, UK,
        Canada, Ireland, New Zealand and Australia markets.

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

        Returns:
            ManyAudiobooks: Response from the API. A set of audiobooks. If one
                of the requested audiobooks is unavailable then you'll find a
                `null` item in the `audiobooks` array where the audiobook
                object would otherwise be.

        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('/audiobooks')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('ids')
                         .value(ids))
            .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(ManyAudiobooks.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_audiobook_chapters(self,
                               id,
                               market=None,
                               limit=20,
                               offset=0):
        """Does a GET request to /audiobooks/{id}/chapters.

        Get Spotify catalog information about an audiobook's chapters.
        Audiobooks are only available within the US, UK, Canada, Ireland, New
        Zealand and Australia markets.

        Args:
            id (str): The request template 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:
            PagingSimplifiedChapterObject: Response from the API. Pages of
                chapters

        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('/audiobooks/{id}/chapters')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .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(PagingSimplifiedChapterObject.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_users_saved_audiobooks(self,
                                   limit=20,
                                   offset=0):
        """Does a GET request to /me/audiobooks.

        Get a list of the audiobooks saved in the current Spotify user's 'Your
        Music' library.

        Args:
            limit (int, optional): The request query parameter. Example: 20
            offset (int, optional): The request query parameter. Example: 0

        Returns:
            PagingSavedAudiobookObject: Response from the API. Pages of saved
                audiobooks

        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('/me/audiobooks')
            .http_method(HttpMethodEnum.GET)
            .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(PagingSavedAudiobookObject.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 save_audiobooks_user(self,
                             ids):
        """Does a PUT request to /me/audiobooks.

        Save one or more audiobooks to the current Spotify user's library.

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

        Returns:
            void: Response from the API. Audiobook(s) are saved to the library

        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('/me/audiobooks')
            .http_method(HttpMethodEnum.PUT)
            .query_param(Parameter()
                         .key('ids')
                         .value(ids))
            .auth(Single('oauth_2_0'))
        ).execute()

    def remove_audiobooks_user(self,
                               ids):
        """Does a DELETE request to /me/audiobooks.

        Remove one or more audiobooks from the Spotify user's library.

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

        Returns:
            void: Response from the API. Audiobook(s) have been removed from
                the library

        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('/me/audiobooks')
            .http_method(HttpMethodEnum.DELETE)
            .query_param(Parameter()
                         .key('ids')
                         .value(ids))
            .auth(Single('oauth_2_0'))
        ).execute()

    def check_users_saved_audiobooks(self,
                                     ids):
        """Does a GET request to /me/audiobooks/contains.

        Check if one or more audiobooks are already saved in the current
        Spotify user's library.

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

        Returns:
            List[bool]: Response from the API. Array of booleans

        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('/me/audiobooks/contains')
            .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)
            .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()
