sdks/java/src/main/java/com/konfigthis/client/api/AuthenticationApi.java
/*
 * SnapTrade
 * Connect brokerage accounts to your app for live positions and trading
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: lyhxr@example.com
 *
 * NOTE: This class is auto generated by Konfig (https://konfigthis.com).
 * Do not edit the class manually.
 */


package com.konfigthis.client.api;

import com.konfigthis.client.ApiCallback;
import com.konfigthis.client.ApiClient;
import com.konfigthis.client.ApiException;
import com.konfigthis.client.ApiResponse;
import com.konfigthis.client.Configuration;
import com.konfigthis.client.Pair;
import com.konfigthis.client.ProgressRequestBody;
import com.konfigthis.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.konfigthis.client.model.DeleteUserResponse;
import com.konfigthis.client.model.EncryptedResponse;
import com.konfigthis.client.model.SnapTradeLoginUserRequestBody;
import com.konfigthis.client.model.SnapTradeRegisterUserRequestBody;
import com.konfigthis.client.model.UserIDandSecret;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;

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

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

    public AuthenticationApi(ApiClient apiClient) throws IllegalArgumentException {
        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;
    }

    private okhttp3.Call deleteSnapTradeUserCall(String userId, 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 = "/snapTrade/deleteUser";

        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 (userId != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("userId", userId));
        }

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

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

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

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

        return deleteSnapTradeUserCall(userId, _callback);

    }


    private ApiResponse<DeleteUserResponse> deleteSnapTradeUserWithHttpInfo(String userId) throws ApiException {
        okhttp3.Call localVarCall = deleteSnapTradeUserValidateBeforeCall(userId, null);
        Type localVarReturnType = new TypeToken<DeleteUserResponse>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    private okhttp3.Call deleteSnapTradeUserAsync(String userId, final ApiCallback<DeleteUserResponse> _callback) throws ApiException {

        okhttp3.Call localVarCall = deleteSnapTradeUserValidateBeforeCall(userId, _callback);
        Type localVarReturnType = new TypeToken<DeleteUserResponse>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }

    public class DeleteSnapTradeUserRequestBuilder {
        private final String userId;

        private DeleteSnapTradeUserRequestBuilder(String userId) {
            this.userId = userId;
        }

        /**
         * Build call for deleteSnapTradeUser
         * @param _callback ApiCallback API callback
         * @return Call to execute
         * @throws ApiException If fail to serialize the request body object
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Delete successful </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
            return deleteSnapTradeUserCall(userId, _callback);
        }


        /**
         * Execute deleteSnapTradeUser request
         * @return DeleteUserResponse
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Delete successful </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public DeleteUserResponse execute() throws ApiException {
            ApiResponse<DeleteUserResponse> localVarResp = deleteSnapTradeUserWithHttpInfo(userId);
            return localVarResp.getResponseBody();
        }

        /**
         * Execute deleteSnapTradeUser request with HTTP info returned
         * @return ApiResponse&lt;DeleteUserResponse&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Delete successful </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public ApiResponse<DeleteUserResponse> executeWithHttpInfo() throws ApiException {
            return deleteSnapTradeUserWithHttpInfo(userId);
        }

        /**
         * Execute deleteSnapTradeUser request (asynchronously)
         * @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 summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Delete successful </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call executeAsync(final ApiCallback<DeleteUserResponse> _callback) throws ApiException {
            return deleteSnapTradeUserAsync(userId, _callback);
        }
    }

    /**
     * Delete user from SnapTrade, disabling all brokerage authorizations and permanently deleting all data associated with the user
     * 
     * @param userId  (required)
     * @return DeleteSnapTradeUserRequestBuilder
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Delete successful </td><td>  -  </td></tr>
        <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
     </table>
     */
    public DeleteSnapTradeUserRequestBuilder deleteSnapTradeUser(String userId) throws IllegalArgumentException {
        if (userId == null) throw new IllegalArgumentException("\"userId\" is required but got null");
            

        return new DeleteSnapTradeUserRequestBuilder(userId);
    }
    private okhttp3.Call getUserJWTCall(String userId, String userSecret, 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 = "/snapTrade/encryptedJWT";

        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 (userId != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("userId", userId));
        }

        if (userSecret != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("userSecret", userSecret));
        }

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

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

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

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

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

        return getUserJWTCall(userId, userSecret, _callback);

    }


    private ApiResponse<EncryptedResponse> getUserJWTWithHttpInfo(String userId, String userSecret) throws ApiException {
        okhttp3.Call localVarCall = getUserJWTValidateBeforeCall(userId, userSecret, null);
        Type localVarReturnType = new TypeToken<EncryptedResponse>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    private okhttp3.Call getUserJWTAsync(String userId, String userSecret, final ApiCallback<EncryptedResponse> _callback) throws ApiException {

        okhttp3.Call localVarCall = getUserJWTValidateBeforeCall(userId, userSecret, _callback);
        Type localVarReturnType = new TypeToken<EncryptedResponse>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }

    public class GetUserJWTRequestBuilder {
        private final String userId;
        private final String userSecret;

        private GetUserJWTRequestBuilder(String userId, String userSecret) {
            this.userId = userId;
            this.userSecret = userSecret;
        }

        /**
         * Build call for getUserJWT
         * @param _callback ApiCallback API callback
         * @return Call to execute
         * @throws ApiException If fail to serialize the request body object
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully obtained encrypted JWT data. See description on how to object JWT token </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
            return getUserJWTCall(userId, userSecret, _callback);
        }


        /**
         * Execute getUserJWT request
         * @return EncryptedResponse
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully obtained encrypted JWT data. See description on how to object JWT token </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public EncryptedResponse execute() throws ApiException {
            ApiResponse<EncryptedResponse> localVarResp = getUserJWTWithHttpInfo(userId, userSecret);
            return localVarResp.getResponseBody();
        }

        /**
         * Execute getUserJWT request with HTTP info returned
         * @return ApiResponse&lt;EncryptedResponse&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully obtained encrypted JWT data. See description on how to object JWT token </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public ApiResponse<EncryptedResponse> executeWithHttpInfo() throws ApiException {
            return getUserJWTWithHttpInfo(userId, userSecret);
        }

        /**
         * Execute getUserJWT request (asynchronously)
         * @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 summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully obtained encrypted JWT data. See description on how to object JWT token </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call executeAsync(final ApiCallback<EncryptedResponse> _callback) throws ApiException {
            return getUserJWTAsync(userId, userSecret, _callback);
        }
    }

    /**
     * Obtains an encrypted JWT tokens that should be decrypted on a user&#39;s local device
     * 
     * @param userId  (required)
     * @param userSecret  (required)
     * @return GetUserJWTRequestBuilder
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Successfully obtained encrypted JWT data. See description on how to object JWT token </td><td>  -  </td></tr>
        <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
     </table>
     */
    public GetUserJWTRequestBuilder getUserJWT(String userId, String userSecret) throws IllegalArgumentException {
        if (userId == null) throw new IllegalArgumentException("\"userId\" is required but got null");
            

        if (userSecret == null) throw new IllegalArgumentException("\"userSecret\" is required but got null");
            

        return new GetUserJWTRequestBuilder(userId, userSecret);
    }
    private okhttp3.Call listSnapTradeUsersCall(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 = "/snapTrade/listUsers";

        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>();

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

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

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

    @SuppressWarnings("rawtypes")
    private okhttp3.Call listSnapTradeUsersValidateBeforeCall(final ApiCallback _callback) throws ApiException {
        return listSnapTradeUsersCall(_callback);

    }


    private ApiResponse<List<String>> listSnapTradeUsersWithHttpInfo() throws ApiException {
        okhttp3.Call localVarCall = listSnapTradeUsersValidateBeforeCall(null);
        Type localVarReturnType = new TypeToken<List<String>>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    private okhttp3.Call listSnapTradeUsersAsync(final ApiCallback<List<String>> _callback) throws ApiException {

        okhttp3.Call localVarCall = listSnapTradeUsersValidateBeforeCall(_callback);
        Type localVarReturnType = new TypeToken<List<String>>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }

    public class ListSnapTradeUsersRequestBuilder {

        private ListSnapTradeUsersRequestBuilder() {
        }

        /**
         * Build call for listSnapTradeUsers
         * @param _callback ApiCallback API callback
         * @return Call to execute
         * @throws ApiException If fail to serialize the request body object
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully generated a list of users </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
            return listSnapTradeUsersCall(_callback);
        }


        /**
         * Execute listSnapTradeUsers request
         * @return List&lt;String&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully generated a list of users </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public List<String> execute() throws ApiException {
            ApiResponse<List<String>> localVarResp = listSnapTradeUsersWithHttpInfo();
            return localVarResp.getResponseBody();
        }

        /**
         * Execute listSnapTradeUsers request with HTTP info returned
         * @return ApiResponse&lt;List&lt;String&gt;&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully generated a list of users </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public ApiResponse<List<String>> executeWithHttpInfo() throws ApiException {
            return listSnapTradeUsersWithHttpInfo();
        }

        /**
         * Execute listSnapTradeUsers request (asynchronously)
         * @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 summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully generated a list of users </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call executeAsync(final ApiCallback<List<String>> _callback) throws ApiException {
            return listSnapTradeUsersAsync(_callback);
        }
    }

    /**
     * Get a list of all SnapTrade users you&#39;ve registered on our platform
     * 
     * @return ListSnapTradeUsersRequestBuilder
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Successfully generated a list of users </td><td>  -  </td></tr>
        <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
     </table>
     */
    public ListSnapTradeUsersRequestBuilder listSnapTradeUsers() throws IllegalArgumentException {
        return new ListSnapTradeUsersRequestBuilder();
    }
    private okhttp3.Call loginSnapTradeUserCall(String userId, String userSecret, SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody, 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 = snapTradeLoginUserRequestBody;

        // create path and map variables
        String localVarPath = "/snapTrade/login";

        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 (userId != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("userId", userId));
        }

        if (userSecret != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("userSecret", userSecret));
        }

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

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

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

    @SuppressWarnings("rawtypes")
    private okhttp3.Call loginSnapTradeUserValidateBeforeCall(String userId, String userSecret, SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'userId' is set
        if (userId == null) {
            throw new ApiException("Missing the required parameter 'userId' when calling loginSnapTradeUser(Async)");
        }

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

        return loginSnapTradeUserCall(userId, userSecret, snapTradeLoginUserRequestBody, _callback);

    }


    private ApiResponse<Object> loginSnapTradeUserWithHttpInfo(String userId, String userSecret, SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody) throws ApiException {
        okhttp3.Call localVarCall = loginSnapTradeUserValidateBeforeCall(userId, userSecret, snapTradeLoginUserRequestBody, null);
        Type localVarReturnType = new TypeToken<Object>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    private okhttp3.Call loginSnapTradeUserAsync(String userId, String userSecret, SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody, final ApiCallback<Object> _callback) throws ApiException {

        okhttp3.Call localVarCall = loginSnapTradeUserValidateBeforeCall(userId, userSecret, snapTradeLoginUserRequestBody, _callback);
        Type localVarReturnType = new TypeToken<Object>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }

    public class LoginSnapTradeUserRequestBuilder {
        private final String userId;
        private final String userSecret;
        private String broker;
        private Boolean immediateRedirect;
        private String customRedirect;
        private String reconnect;
        private String connectionType;

        private LoginSnapTradeUserRequestBuilder(String userId, String userSecret) {
            this.userId = userId;
            this.userSecret = userSecret;
        }

        /**
         * Set broker
         * @param broker  (optional)
         * @return LoginSnapTradeUserRequestBuilder
         */
        public LoginSnapTradeUserRequestBuilder broker(String broker) {
            this.broker = broker;
            return this;
        }
        
        /**
         * Set immediateRedirect
         * @param immediateRedirect  (optional)
         * @return LoginSnapTradeUserRequestBuilder
         */
        public LoginSnapTradeUserRequestBuilder immediateRedirect(Boolean immediateRedirect) {
            this.immediateRedirect = immediateRedirect;
            return this;
        }
        
        /**
         * Set customRedirect
         * @param customRedirect  (optional)
         * @return LoginSnapTradeUserRequestBuilder
         */
        public LoginSnapTradeUserRequestBuilder customRedirect(String customRedirect) {
            this.customRedirect = customRedirect;
            return this;
        }
        
        /**
         * Set reconnect
         * @param reconnect  (optional)
         * @return LoginSnapTradeUserRequestBuilder
         */
        public LoginSnapTradeUserRequestBuilder reconnect(String reconnect) {
            this.reconnect = reconnect;
            return this;
        }
        
        /**
         * Set connectionType
         * @param connectionType  (optional)
         * @return LoginSnapTradeUserRequestBuilder
         */
        public LoginSnapTradeUserRequestBuilder connectionType(String connectionType) {
            this.connectionType = connectionType;
            return this;
        }
        
        /**
         * Build call for loginSnapTradeUser
         * @param _callback ApiCallback API callback
         * @return Call to execute
         * @throws ApiException If fail to serialize the request body object
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Login successful. Redirect user to provided URI in response </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
            SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody = buildBodyParams();
            return loginSnapTradeUserCall(userId, userSecret, snapTradeLoginUserRequestBody, _callback);
        }

        private SnapTradeLoginUserRequestBody buildBodyParams() {
            SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody = new SnapTradeLoginUserRequestBody();
            snapTradeLoginUserRequestBody.broker(this.broker);
            snapTradeLoginUserRequestBody.immediateRedirect(this.immediateRedirect);
            snapTradeLoginUserRequestBody.customRedirect(this.customRedirect);
            snapTradeLoginUserRequestBody.reconnect(this.reconnect);
            if (this.connectionType != null)
            snapTradeLoginUserRequestBody.connectionType(SnapTradeLoginUserRequestBody.ConnectionTypeEnum.fromValue(this.connectionType));
            return snapTradeLoginUserRequestBody;
        }

        /**
         * Execute loginSnapTradeUser request
         * @return Object
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Login successful. Redirect user to provided URI in response </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public Object execute() throws ApiException {
            SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody = buildBodyParams();
            ApiResponse<Object> localVarResp = loginSnapTradeUserWithHttpInfo(userId, userSecret, snapTradeLoginUserRequestBody);
            return localVarResp.getResponseBody();
        }

        /**
         * Execute loginSnapTradeUser request with HTTP info returned
         * @return ApiResponse&lt;Object&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Login successful. Redirect user to provided URI in response </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public ApiResponse<Object> executeWithHttpInfo() throws ApiException {
            SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody = buildBodyParams();
            return loginSnapTradeUserWithHttpInfo(userId, userSecret, snapTradeLoginUserRequestBody);
        }

        /**
         * Execute loginSnapTradeUser request (asynchronously)
         * @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 summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Login successful. Redirect user to provided URI in response </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call executeAsync(final ApiCallback<Object> _callback) throws ApiException {
            SnapTradeLoginUserRequestBody snapTradeLoginUserRequestBody = buildBodyParams();
            return loginSnapTradeUserAsync(userId, userSecret, snapTradeLoginUserRequestBody, _callback);
        }
    }

    /**
     * Generate a redirect URI to securely login a user to the SnapTrade Connection Portal
     * 
     * @param userId  (required)
     * @param userSecret  (required)
     * @return LoginSnapTradeUserRequestBuilder
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Login successful. Redirect user to provided URI in response </td><td>  -  </td></tr>
        <tr><td> 500 </td><td> Unexpected Error </td><td>  -  </td></tr>
     </table>
     */
    public LoginSnapTradeUserRequestBuilder loginSnapTradeUser(String userId, String userSecret) throws IllegalArgumentException {
        if (userId == null) throw new IllegalArgumentException("\"userId\" is required but got null");
            

        if (userSecret == null) throw new IllegalArgumentException("\"userSecret\" is required but got null");
            

        return new LoginSnapTradeUserRequestBuilder(userId, userSecret);
    }
    private okhttp3.Call registerSnapTradeUserCall(SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody, 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 = snapTradeRegisterUserRequestBody;

        // create path and map variables
        String localVarPath = "/snapTrade/registerUser";

        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>();

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

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

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

    @SuppressWarnings("rawtypes")
    private okhttp3.Call registerSnapTradeUserValidateBeforeCall(SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'snapTradeRegisterUserRequestBody' is set
        if (snapTradeRegisterUserRequestBody == null) {
            throw new ApiException("Missing the required parameter 'snapTradeRegisterUserRequestBody' when calling registerSnapTradeUser(Async)");
        }

        return registerSnapTradeUserCall(snapTradeRegisterUserRequestBody, _callback);

    }


    private ApiResponse<UserIDandSecret> registerSnapTradeUserWithHttpInfo(SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody) throws ApiException {
        okhttp3.Call localVarCall = registerSnapTradeUserValidateBeforeCall(snapTradeRegisterUserRequestBody, null);
        Type localVarReturnType = new TypeToken<UserIDandSecret>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    private okhttp3.Call registerSnapTradeUserAsync(SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody, final ApiCallback<UserIDandSecret> _callback) throws ApiException {

        okhttp3.Call localVarCall = registerSnapTradeUserValidateBeforeCall(snapTradeRegisterUserRequestBody, _callback);
        Type localVarReturnType = new TypeToken<UserIDandSecret>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }

    public class RegisterSnapTradeUserRequestBuilder {
        private String userId;
        private String rsaPublicKey;

        private RegisterSnapTradeUserRequestBuilder() {
        }

        /**
         * Set userId
         * @param userId SnapTrade User ID. Provided by SnapTrade Partner. Can be any string, as long as it&#39;s unique to a user (optional)
         * @return RegisterSnapTradeUserRequestBuilder
         */
        public RegisterSnapTradeUserRequestBuilder userId(String userId) {
            this.userId = userId;
            return this;
        }
        
        /**
         * Set rsaPublicKey
         * @param rsaPublicKey Open SSH RSA public key (optional)
         * @return RegisterSnapTradeUserRequestBuilder
         */
        public RegisterSnapTradeUserRequestBuilder rsaPublicKey(String rsaPublicKey) {
            this.rsaPublicKey = rsaPublicKey;
            return this;
        }
        
        /**
         * Build call for registerSnapTradeUser
         * @param _callback ApiCallback API callback
         * @return Call to execute
         * @throws ApiException If fail to serialize the request body object
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully registered user </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
            SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody = buildBodyParams();
            return registerSnapTradeUserCall(snapTradeRegisterUserRequestBody, _callback);
        }

        private SnapTradeRegisterUserRequestBody buildBodyParams() {
            SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody = new SnapTradeRegisterUserRequestBody();
            snapTradeRegisterUserRequestBody.userId(this.userId);
            snapTradeRegisterUserRequestBody.rsaPublicKey(this.rsaPublicKey);
            return snapTradeRegisterUserRequestBody;
        }

        /**
         * Execute registerSnapTradeUser request
         * @return UserIDandSecret
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully registered user </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public UserIDandSecret execute() throws ApiException {
            SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody = buildBodyParams();
            ApiResponse<UserIDandSecret> localVarResp = registerSnapTradeUserWithHttpInfo(snapTradeRegisterUserRequestBody);
            return localVarResp.getResponseBody();
        }

        /**
         * Execute registerSnapTradeUser request with HTTP info returned
         * @return ApiResponse&lt;UserIDandSecret&gt;
         * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
         * @http.response.details
         <table summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully registered user </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public ApiResponse<UserIDandSecret> executeWithHttpInfo() throws ApiException {
            SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody = buildBodyParams();
            return registerSnapTradeUserWithHttpInfo(snapTradeRegisterUserRequestBody);
        }

        /**
         * Execute registerSnapTradeUser request (asynchronously)
         * @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 summary="Response Details" border="1">
            <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
            <tr><td> 200 </td><td> Successfully registered user </td><td>  -  </td></tr>
            <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
         </table>
         */
        public okhttp3.Call executeAsync(final ApiCallback<UserIDandSecret> _callback) throws ApiException {
            SnapTradeRegisterUserRequestBody snapTradeRegisterUserRequestBody = buildBodyParams();
            return registerSnapTradeUserAsync(snapTradeRegisterUserRequestBody, _callback);
        }
    }

    /**
     * Register user with SnapTrade in order to create secure brokerage authorizations
     * 
     * @param snapTradeRegisterUserRequestBody  (required)
     * @return RegisterSnapTradeUserRequestBuilder
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> Successfully registered user </td><td>  -  </td></tr>
        <tr><td> 500 </td><td> Unexpected error </td><td>  -  </td></tr>
     </table>
     */
    public RegisterSnapTradeUserRequestBuilder registerSnapTradeUser() throws IllegalArgumentException {
        return new RegisterSnapTradeUserRequestBuilder();
    }
}
