/*
 * Cloudera Manager API
 * <h1>Cloudera Manager API v50</h1>       <p>Introduced in Cloudera Manager 7.8.1</p>       <p><a href=\"http://www.cloudera.com/documentation.html\">Cloudera Product Documentation</a></p>
 *
 * OpenAPI spec version: 7.8.1
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */


package com.cloudera.api.swagger;

import com.cloudera.api.swagger.client.ApiCallback;
import com.cloudera.api.swagger.client.ApiClient;
import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.client.ApiResponse;
import com.cloudera.api.swagger.client.Configuration;
import com.cloudera.api.swagger.client.Pair;
import com.cloudera.api.swagger.client.ProgressRequestBody;
import com.cloudera.api.swagger.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.cloudera.api.swagger.model.ApiCommand;
import com.cloudera.api.swagger.model.ApiCreateEnvironment;
import com.cloudera.api.swagger.model.ApiRemoteDataContext;

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

public class CdpResourceApi {
    private ApiClient apiClient;

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

    public CdpResourceApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for createEnvironmentCommand
     * @param serviceName  (optional)
     * @param body  (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call createEnvironmentCommandCall(String serviceName, ApiCreateEnvironment body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/cdp/createEnvironment";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (serviceName != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "serviceName", serviceName));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

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

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

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call createEnvironmentCommandValidateBeforeCall(String serviceName, ApiCreateEnvironment body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        
        com.squareup.okhttp.Call call = createEnvironmentCommandCall(serviceName, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Create an environment in ECS.
     * Create an environment in ECS
     * @param serviceName  (optional)
     * @param body  (optional)
     * @return ApiCommand
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCommand createEnvironmentCommand(String serviceName, ApiCreateEnvironment body) throws ApiException {
        ApiResponse<ApiCommand> resp = createEnvironmentCommandWithHttpInfo(serviceName, body);
        return resp.getData();
    }

    /**
     * Create an environment in ECS.
     * Create an environment in ECS
     * @param serviceName  (optional)
     * @param body  (optional)
     * @return ApiResponse&lt;ApiCommand&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCommand> createEnvironmentCommandWithHttpInfo(String serviceName, ApiCreateEnvironment body) throws ApiException {
        com.squareup.okhttp.Call call = createEnvironmentCommandValidateBeforeCall(serviceName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Create an environment in ECS. (asynchronously)
     * Create an environment in ECS
     * @param serviceName  (optional)
     * @param body  (optional)
     * @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
     */
    public com.squareup.okhttp.Call createEnvironmentCommandAsync(String serviceName, ApiCreateEnvironment body, final ApiCallback<ApiCommand> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = createEnvironmentCommandValidateBeforeCall(serviceName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for getRemoteContext
     * @param dataContextName The name of the DataContext. (required)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call getRemoteContextCall(String dataContextName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cdp/remoteContext/byContext/{dataContextName}"
            .replaceAll("\\{" + "dataContextName" + "\\}", apiClient.escapeString(dataContextName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

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

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

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call getRemoteContextValidateBeforeCall(String dataContextName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'dataContextName' is set
        if (dataContextName == null) {
            throw new ApiException("Missing the required parameter 'dataContextName' when calling getRemoteContext(Async)");
        }
        
        
        com.squareup.okhttp.Call call = getRemoteContextCall(dataContextName, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster.
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param dataContextName The name of the DataContext. (required)
     * @return ApiRemoteDataContext
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiRemoteDataContext getRemoteContext(String dataContextName) throws ApiException {
        ApiResponse<ApiRemoteDataContext> resp = getRemoteContextWithHttpInfo(dataContextName);
        return resp.getData();
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster.
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param dataContextName The name of the DataContext. (required)
     * @return ApiResponse&lt;ApiRemoteDataContext&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiRemoteDataContext> getRemoteContextWithHttpInfo(String dataContextName) throws ApiException {
        com.squareup.okhttp.Call call = getRemoteContextValidateBeforeCall(dataContextName, null, null);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster. (asynchronously)
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param dataContextName The name of the DataContext. (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
     */
    public com.squareup.okhttp.Call getRemoteContextAsync(String dataContextName, final ApiCallback<ApiRemoteDataContext> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = getRemoteContextValidateBeforeCall(dataContextName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for getRemoteContextByCluster
     * @param clusterName The name of the DataContext. (required)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call getRemoteContextByClusterCall(String clusterName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cdp/remoteContext/byCluster/{clusterName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

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

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

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call getRemoteContextByClusterValidateBeforeCall(String clusterName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'clusterName' is set
        if (clusterName == null) {
            throw new ApiException("Missing the required parameter 'clusterName' when calling getRemoteContextByCluster(Async)");
        }
        
        
        com.squareup.okhttp.Call call = getRemoteContextByClusterCall(clusterName, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster.
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param clusterName The name of the DataContext. (required)
     * @return ApiRemoteDataContext
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiRemoteDataContext getRemoteContextByCluster(String clusterName) throws ApiException {
        ApiResponse<ApiRemoteDataContext> resp = getRemoteContextByClusterWithHttpInfo(clusterName);
        return resp.getData();
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster.
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param clusterName The name of the DataContext. (required)
     * @return ApiResponse&lt;ApiRemoteDataContext&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiRemoteDataContext> getRemoteContextByClusterWithHttpInfo(String clusterName) throws ApiException {
        com.squareup.okhttp.Call call = getRemoteContextByClusterValidateBeforeCall(clusterName, null, null);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get a JSON for creating a remote data context in a Workload cluster. (asynchronously)
     * Get a JSON for creating a remote data context in a Workload cluster.
     * @param clusterName The name of the DataContext. (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
     */
    public com.squareup.okhttp.Call getRemoteContextByClusterAsync(String clusterName, final ApiCallback<ApiRemoteDataContext> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = getRemoteContextByClusterValidateBeforeCall(clusterName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for postRemoteContext
     * @param body  (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call postRemoteContextCall(ApiRemoteDataContext body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/cdp/remoteContext";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

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

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

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call postRemoteContextValidateBeforeCall(ApiRemoteDataContext body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        
        com.squareup.okhttp.Call call = postRemoteContextCall(body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Create or update the remote data context in the Workload cluster.
     * Create or update the remote data context in the Workload cluster.
     * @param body  (optional)
     * @return ApiRemoteDataContext
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiRemoteDataContext postRemoteContext(ApiRemoteDataContext body) throws ApiException {
        ApiResponse<ApiRemoteDataContext> resp = postRemoteContextWithHttpInfo(body);
        return resp.getData();
    }

    /**
     * Create or update the remote data context in the Workload cluster.
     * Create or update the remote data context in the Workload cluster.
     * @param body  (optional)
     * @return ApiResponse&lt;ApiRemoteDataContext&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiRemoteDataContext> postRemoteContextWithHttpInfo(ApiRemoteDataContext body) throws ApiException {
        com.squareup.okhttp.Call call = postRemoteContextValidateBeforeCall(body, null, null);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Create or update the remote data context in the Workload cluster. (asynchronously)
     * Create or update the remote data context in the Workload cluster.
     * @param body  (optional)
     * @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
     */
    public com.squareup.okhttp.Call postRemoteContextAsync(ApiRemoteDataContext body, final ApiCallback<ApiRemoteDataContext> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = postRemoteContextValidateBeforeCall(body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiRemoteDataContext>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
