# coding: utf-8

"""
    CardPay REST API

    Welcome to the CardPay REST API. The CardPay API uses HTTP verbs and a [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) resources endpoint structure (see more info about REST). Request and response payloads are formatted as JSON. Merchant uses API to create payments, refunds, payouts or recurrings, check or update transaction status and get information about created transactions. In API authentication process based on [OAuth 2.0](https://oauth.net/2/) standard. For recent changes see changelog section.  # noqa: E501

    OpenAPI spec version: 3.0
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from cardpay.api_client import ApiClient


class AuthApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def obtain_tokens(self, grant_type, **kwargs):  # noqa: E501
        """Get authorization token  # noqa: E501

        :param str grant_type: Token request credentials representation (required)
        :param str password: Terminal password value (only for [password] grant type)
        :param str refresh_token: Refresh token string (only for [refresh_token] grant type)
        :param str terminal_code: Terminal code value
        :return: ApiTokens
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.obtain_tokens_with_http_info(grant_type, **kwargs)  # noqa: E501
        return data

    def obtain_tokens_with_http_info(self, grant_type, **kwargs):  # noqa: E501
        """Get authorization token  # noqa: E501

        :param str grant_type: Token request credentials representation (required)
        :param str password: Terminal password value (only for [password] grant type)
        :param str refresh_token: Refresh token string (only for [refresh_token] grant type)
        :param str terminal_code: Terminal code value
        :return: ApiTokens
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = [
            "grant_type",
            "password",
            "refresh_token",
            "terminal_code",
        ]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method obtain_tokens" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'grant_type' is set
        if "grant_type" not in params or params["grant_type"] is None:
            raise ValueError(
                "Missing the required parameter `grant_type` when calling `obtain_tokens`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}
        if "grant_type" in params:
            form_params.append(("grant_type", params["grant_type"]))  # noqa: E501
        if "password" in params:
            form_params.append(("password", params["password"]))  # noqa: E501
        if "refresh_token" in params:
            form_params.append(("refresh_token", params["refresh_token"]))  # noqa: E501
        if "terminal_code" in params:
            form_params.append(("terminal_code", params["terminal_code"]))  # noqa: E501

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501
        # HTTP header `Content-Type`
        header_params[
            "Content-Type"
        ] = self.api_client.select_header_content_type(  # noqa: E501
            ["application/x-www-form-urlencoded"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/auth/token",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="ApiTokens",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
