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

"""
spotifywebapiwithfixesandimprovementsfromsonallux

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

import warnings
from enum import Enum
from apimatic_core.http.configurations.http_client_configuration import HttpClientConfiguration
from apimatic_requests_client_adapter.requests_client import RequestsClient


class Environment(Enum):
    """An enum for SDK environments"""
    PRODUCTION = 0


class Server(Enum):
    """An enum for API servers"""
    DEFAULT = 0
    AUTH_SERVER = 1


class Configuration(HttpClientConfiguration):
    """A class used for configuring the SDK by a user.
    """

    @property
    def environment(self):
        return self._environment

    @property
    def o_auth_client_id(self):
        return self._authorization_code_auth_credentials.o_auth_client_id

    @property
    def o_auth_client_secret(self):
        return self._authorization_code_auth_credentials.o_auth_client_secret

    @property
    def o_auth_redirect_uri(self):
        return self._authorization_code_auth_credentials.o_auth_redirect_uri

    @property
    def o_auth_scopes(self):
        return self._authorization_code_auth_credentials.o_auth_scopes

    @property
    def o_auth_token(self):
        return self._authorization_code_auth_credentials.o_auth_token

    @property
    def authorization_code_auth_credentials(self):
        return self._authorization_code_auth_credentials

    def __init__(self, http_client_instance=None,
                 override_http_client_configuration=False, http_call_back=None,
                 timeout=60, max_retries=0, backoff_factor=2,
                 retry_statuses=None, retry_methods=None,
                 environment=Environment.PRODUCTION, o_auth_client_id=None,
                 o_auth_client_secret=None, o_auth_redirect_uri=None,
                 o_auth_token=None, o_auth_scopes=None,
                 authorization_code_auth_credentials=None):
        if retry_methods is None:
            retry_methods = ['GET', 'PUT']

        if retry_statuses is None:
            retry_statuses = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]

        super().__init__(http_client_instance,
                         override_http_client_configuration, http_call_back,
                         timeout, max_retries, backoff_factor, retry_statuses,
                         retry_methods)

        # Current API environment
        self._environment = environment

        self._authorization_code_auth_credentials = self.create_auth_credentials_object(
            o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri,
            o_auth_token, o_auth_scopes, authorization_code_auth_credentials)

        # The Http Client to use for making requests.
        self.set_http_client(self.create_http_client())

    def clone_with(self, http_client_instance=None,
                   override_http_client_configuration=None, http_call_back=None,
                   timeout=None, max_retries=None, backoff_factor=None,
                   retry_statuses=None, retry_methods=None, environment=None,
                   o_auth_client_id=None, o_auth_client_secret=None,
                   o_auth_redirect_uri=None, o_auth_token=None,
                   o_auth_scopes=None, authorization_code_auth_credentials=None):
        http_client_instance = http_client_instance or self.http_client_instance
        override_http_client_configuration = override_http_client_configuration or self.override_http_client_configuration
        http_call_back = http_call_back or self.http_callback
        timeout = timeout or self.timeout
        max_retries = max_retries or self.max_retries
        backoff_factor = backoff_factor or self.backoff_factor
        retry_statuses = retry_statuses or self.retry_statuses
        retry_methods = retry_methods or self.retry_methods
        environment = environment or self.environment
        authorization_code_auth_credentials = self.create_auth_credentials_object(
            o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri,
            o_auth_token, o_auth_scopes,
            authorization_code_auth_credentials or self.authorization_code_auth_credentials,
            stack_level=3)
        return Configuration(
            http_client_instance=http_client_instance,
            override_http_client_configuration=override_http_client_configuration,
            http_call_back=http_call_back, timeout=timeout, max_retries=max_retries,
            backoff_factor=backoff_factor, retry_statuses=retry_statuses,
            retry_methods=retry_methods, environment=environment,
            authorization_code_auth_credentials=authorization_code_auth_credentials
        )

    def create_http_client(self):
        return RequestsClient(
            timeout=self.timeout, max_retries=self.max_retries,
            backoff_factor=self.backoff_factor, retry_statuses=self.retry_statuses,
            retry_methods=self.retry_methods,
            http_client_instance=self.http_client_instance,
            override_http_client_configuration=self.override_http_client_configuration,
            response_factory=self.http_response_factory
        )

    # All the environments the SDK can run in
    environments = {
        Environment.PRODUCTION: {
            Server.DEFAULT: 'https://api.spotify.com/v1',
            Server.AUTH_SERVER: 'https://accounts.spotify.com'
        }
    }

    def get_base_uri(self, server=Server.DEFAULT):
        """Generates the appropriate base URI for the environment and the
        server.

        Args:
            server (Configuration.Server): The server enum for which the base
            URI is required.

        Returns:
            String: The base URI.

        """
        return self.environments[self.environment][server]

    @staticmethod
    def create_auth_credentials_object(o_auth_client_id, o_auth_client_secret,
                                       o_auth_redirect_uri, o_auth_token,
                                       o_auth_scopes,
                                       authorization_code_auth_credentials,
                                       stack_level=4):
        if o_auth_client_id is None \
                and o_auth_client_secret is None \
                and o_auth_redirect_uri is None \
                and o_auth_token is None \
                and o_auth_scopes is None:
            return authorization_code_auth_credentials

        warnings.warn(message=('The \'o_auth_client_id\', \'o_auth_client_secre'
                               't\', \'o_auth_redirect_uri\', \'o_auth_token\','
                               ' \'o_auth_scopes\' params are deprecated. Use '
                               '\'authorization_code_auth_credentials\' param i'
                               'nstead.'),
                      category=DeprecationWarning,
                      stacklevel=stack_level)

        if authorization_code_auth_credentials is not None:
            return authorization_code_auth_credentials.clone_with(
                o_auth_client_id, o_auth_client_secret, o_auth_redirect_uri,
                o_auth_token, o_auth_scopes)

        from spotifywebapiwithfixesandimprovementsfromsonallux.http.auth.o_auth_2 import AuthorizationCodeAuthCredentials
        return AuthorizationCodeAuthCredentials(o_auth_client_id,
                                                o_auth_client_secret,
                                                o_auth_redirect_uri,
                                                o_auth_token, o_auth_scopes)
