/*
 * Michelin North America Order-to-Cash APIs
 * These APIs will help you to do business transactions with Michelin.  <br><br><b>Authentication details:</b><br> <br><u>Option A:</u> OAuth2 Client Credentials (recommended) <br><u>Option B:</u> API Key + Basic Authentication (not recommended) <br><br>To request your access, please contact your representative. <br><br>Our services are based on the EDIWHEEL standards. <br>You can find more information on the <a href=\"https://www.ediwheel.com/\" target=\"_blank\">EDIWHEEL website</a>. 
 *
 * The version of the OpenAPI document: 1.0.1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package com.michelin.adk.amn.o2c;

import com.michelin.adk.amn.ApiCallback;
import com.michelin.adk.amn.ApiClient;
import com.michelin.adk.amn.ApiException;
import com.michelin.adk.amn.ApiResponse;
import com.michelin.adk.amn.Configuration;
import com.michelin.adk.amn.Pair;
import com.michelin.adk.amn.ProgressRequestBody;
import com.michelin.adk.amn.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.michelin.adk.amn.o2c.model.AuthenticationError;
import com.michelin.adk.amn.o2c.model.AuthenticationTokenResponse;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AuthenticationApi {
    private ApiClient localVarApiClient;
    private int localHostIndex;
    private String localCustomBaseUrl;

    public AuthenticationApi() {
        this(Configuration.getDefaultApiClient());
    }

    public AuthenticationApi(ApiClient apiClient) {
        this.localVarApiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return localVarApiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.localVarApiClient = apiClient;
    }

    public int getHostIndex() {
        return localHostIndex;
    }

    public void setHostIndex(int hostIndex) {
        this.localHostIndex = hostIndex;
    }

    public String getCustomBaseUrl() {
        return localCustomBaseUrl;
    }

    public void setCustomBaseUrl(String customBaseUrl) {
        this.localCustomBaseUrl = customBaseUrl;
    }

    /**
     * Build call for idpV2B2bOauth2TokenPost
     * @param grantType  (required)
     * @param clientId  (required)
     * @param clientSecret  (required)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> Bad Request </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> Authentication information is missing or invalid </td><td>  * WWW_Authenticate -  <br>  </td></tr>
     </table>
     */
    public okhttp3.Call idpV2B2bOauth2TokenPostCall(String grantType, String clientId, String clientSecret, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/idp/v2/b2b/oauth2/token";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        if (grantType != null) {
            localVarFormParams.put("grant_type", grantType);
        }

        if (clientId != null) {
            localVarFormParams.put("client_id", clientId);
        }

        if (clientSecret != null) {
            localVarFormParams.put("client_secret", clientSecret);
        }

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
            "application/x-www-form-urlencoded"
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        String[] localVarAuthNames = new String[] {  };
        return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call idpV2B2bOauth2TokenPostValidateBeforeCall(String grantType, String clientId, String clientSecret, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'grantType' is set
        if (grantType == null) {
            throw new ApiException("Missing the required parameter 'grantType' when calling idpV2B2bOauth2TokenPost(Async)");
        }

        // verify the required parameter 'clientId' is set
        if (clientId == null) {
            throw new ApiException("Missing the required parameter 'clientId' when calling idpV2B2bOauth2TokenPost(Async)");
        }

        // verify the required parameter 'clientSecret' is set
        if (clientSecret == null) {
            throw new ApiException("Missing the required parameter 'clientSecret' when calling idpV2B2bOauth2TokenPost(Async)");
        }

        return idpV2B2bOauth2TokenPostCall(grantType, clientId, clientSecret, _callback);

    }

    /**
     * Obtain a token to consume the other APIs.
     * This API will give you a valid authorization token to consume the other APIs.
     * @param grantType  (required)
     * @param clientId  (required)
     * @param clientSecret  (required)
     * @return AuthenticationTokenResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> Bad Request </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> Authentication information is missing or invalid </td><td>  * WWW_Authenticate -  <br>  </td></tr>
     </table>
     */
    public AuthenticationTokenResponse idpV2B2bOauth2TokenPost(String grantType, String clientId, String clientSecret) throws ApiException {
        ApiResponse<AuthenticationTokenResponse> localVarResp = idpV2B2bOauth2TokenPostWithHttpInfo(grantType, clientId, clientSecret);
        return localVarResp.getData();
    }

    /**
     * Obtain a token to consume the other APIs.
     * This API will give you a valid authorization token to consume the other APIs.
     * @param grantType  (required)
     * @param clientId  (required)
     * @param clientSecret  (required)
     * @return ApiResponse&lt;AuthenticationTokenResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> Bad Request </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> Authentication information is missing or invalid </td><td>  * WWW_Authenticate -  <br>  </td></tr>
     </table>
     */
    public ApiResponse<AuthenticationTokenResponse> idpV2B2bOauth2TokenPostWithHttpInfo(String grantType, String clientId, String clientSecret) throws ApiException {
        okhttp3.Call localVarCall = idpV2B2bOauth2TokenPostValidateBeforeCall(grantType, clientId, clientSecret, null);
        Type localVarReturnType = new TypeToken<AuthenticationTokenResponse>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Obtain a token to consume the other APIs. (asynchronously)
     * This API will give you a valid authorization token to consume the other APIs.
     * @param grantType  (required)
     * @param clientId  (required)
     * @param clientSecret  (required)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table border="1">
       <caption>Response Details</caption>
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> Bad Request </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> Authentication information is missing or invalid </td><td>  * WWW_Authenticate -  <br>  </td></tr>
     </table>
     */
    public okhttp3.Call idpV2B2bOauth2TokenPostAsync(String grantType, String clientId, String clientSecret, final ApiCallback<AuthenticationTokenResponse> _callback) throws ApiException {

        okhttp3.Call localVarCall = idpV2B2bOauth2TokenPostValidateBeforeCall(grantType, clientId, clientSecret, _callback);
        Type localVarReturnType = new TypeToken<AuthenticationTokenResponse>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
}
