/*
 * Cloudera Manager API
 * <h1>Cloudera Manager API v57</h1>       <p>Introduced in Cloudera Manager 7.13.1</p>       <p><a href=\"http://www.cloudera.com/documentation.html\">Cloudera Product Documentation</a></p>
 *
 * OpenAPI spec version: 7.13.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.ApiHostRefList;
import com.cloudera.api.swagger.model.ApiHostTemplate;
import com.cloudera.api.swagger.model.ApiHostTemplateList;

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

public class HostTemplatesResourceApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for applyHostTemplate
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param body List of hosts to apply the host template to. (optional)
     * @param runConfigRules Whether to run the rules engine to automatically configure roles present on the hosts (optional, default to false)
     * @param startRoles Whether to start the newly created roles or not. (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 okhttp3.Call applyHostTemplateCall(String clusterName, String hostTemplateName, ApiHostRefList body, Boolean runConfigRules, Boolean startRoles, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates/{hostTemplateName}/commands/applyHostTemplate"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "hostTemplateName" + "\\}", apiClient.escapeString(hostTemplateName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        if (runConfigRules != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("runConfigRules", runConfigRules));
        if (startRoles != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("startRoles", startRoles));

        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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call applyHostTemplateValidateBeforeCall(String clusterName, String hostTemplateName, ApiHostRefList body, Boolean runConfigRules, Boolean startRoles, 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 applyHostTemplate(Async)");
        }
        // verify the required parameter 'hostTemplateName' is set
        if (hostTemplateName == null) {
            throw new ApiException("Missing the required parameter 'hostTemplateName' when calling applyHostTemplate(Async)");
        }

        okhttp3.Call call = applyHostTemplateCall(clusterName, hostTemplateName, body, runConfigRules, startRoles, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Applies a host template to a collection of hosts.
     * Applies a host template to a collection of hosts. This will create a role for each role config group on each of the hosts. &lt;p&gt; The provided hosts must not have any existing roles on them and if the cluster is not using parcels, the hosts must have a CDH version matching that of the cluster version. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param body List of hosts to apply the host template to. (optional)
     * @param runConfigRules Whether to run the rules engine to automatically configure roles present on the hosts (optional, default to false)
     * @param startRoles Whether to start the newly created roles or not. (optional)
     * @return ApiCommand
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCommand applyHostTemplate(String clusterName, String hostTemplateName, ApiHostRefList body, Boolean runConfigRules, Boolean startRoles) throws ApiException {
        ApiResponse<ApiCommand> resp = applyHostTemplateWithHttpInfo(clusterName, hostTemplateName, body, runConfigRules, startRoles);
        return resp.getData();
    }

    /**
     * Applies a host template to a collection of hosts.
     * Applies a host template to a collection of hosts. This will create a role for each role config group on each of the hosts. &lt;p&gt; The provided hosts must not have any existing roles on them and if the cluster is not using parcels, the hosts must have a CDH version matching that of the cluster version. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param body List of hosts to apply the host template to. (optional)
     * @param runConfigRules Whether to run the rules engine to automatically configure roles present on the hosts (optional, default to false)
     * @param startRoles Whether to start the newly created roles or not. (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> applyHostTemplateWithHttpInfo(String clusterName, String hostTemplateName, ApiHostRefList body, Boolean runConfigRules, Boolean startRoles) throws ApiException {
        okhttp3.Call call = applyHostTemplateValidateBeforeCall(clusterName, hostTemplateName, body, runConfigRules, startRoles, null, null);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Applies a host template to a collection of hosts. (asynchronously)
     * Applies a host template to a collection of hosts. This will create a role for each role config group on each of the hosts. &lt;p&gt; The provided hosts must not have any existing roles on them and if the cluster is not using parcels, the hosts must have a CDH version matching that of the cluster version. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param body List of hosts to apply the host template to. (optional)
     * @param runConfigRules Whether to run the rules engine to automatically configure roles present on the hosts (optional, default to false)
     * @param startRoles Whether to start the newly created roles or not. (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 okhttp3.Call applyHostTemplateAsync(String clusterName, String hostTemplateName, ApiHostRefList body, Boolean runConfigRules, Boolean startRoles, 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);
                }
            };
        }

        okhttp3.Call call = applyHostTemplateValidateBeforeCall(clusterName, hostTemplateName, body, runConfigRules, startRoles, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for createHostTemplates
     * @param clusterName  (required)
     * @param body The list of host templates to create. (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 okhttp3.Call createHostTemplatesCall(String clusterName, ApiHostTemplateList body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = 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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call createHostTemplatesValidateBeforeCall(String clusterName, ApiHostTemplateList body, 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 createHostTemplates(Async)");
        }

        okhttp3.Call call = createHostTemplatesCall(clusterName, body, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Creates new host templates.
     * Creates new host templates. &lt;p&gt; Host template names must be unique across clusters. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param body The list of host templates to create. (optional)
     * @return ApiHostTemplateList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiHostTemplateList createHostTemplates(String clusterName, ApiHostTemplateList body) throws ApiException {
        ApiResponse<ApiHostTemplateList> resp = createHostTemplatesWithHttpInfo(clusterName, body);
        return resp.getData();
    }

    /**
     * Creates new host templates.
     * Creates new host templates. &lt;p&gt; Host template names must be unique across clusters. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param body The list of host templates to create. (optional)
     * @return ApiResponse&lt;ApiHostTemplateList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiHostTemplateList> createHostTemplatesWithHttpInfo(String clusterName, ApiHostTemplateList body) throws ApiException {
        okhttp3.Call call = createHostTemplatesValidateBeforeCall(clusterName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiHostTemplateList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Creates new host templates. (asynchronously)
     * Creates new host templates. &lt;p&gt; Host template names must be unique across clusters. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param body The list of host templates to create. (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 okhttp3.Call createHostTemplatesAsync(String clusterName, ApiHostTemplateList body, final ApiCallback<ApiHostTemplateList> 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);
                }
            };
        }

        okhttp3.Call call = createHostTemplatesValidateBeforeCall(clusterName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiHostTemplateList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for deleteHostTemplate
     * @param clusterName  (required)
     * @param hostTemplateName Host template to delete. (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 okhttp3.Call deleteHostTemplateCall(String clusterName, String hostTemplateName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates/{hostTemplateName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "hostTemplateName" + "\\}", apiClient.escapeString(hostTemplateName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = 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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call deleteHostTemplateValidateBeforeCall(String clusterName, String hostTemplateName, 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 deleteHostTemplate(Async)");
        }
        // verify the required parameter 'hostTemplateName' is set
        if (hostTemplateName == null) {
            throw new ApiException("Missing the required parameter 'hostTemplateName' when calling deleteHostTemplate(Async)");
        }

        okhttp3.Call call = deleteHostTemplateCall(clusterName, hostTemplateName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Deletes a host template.
     * Deletes a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to delete. (required)
     * @return ApiHostTemplate
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiHostTemplate deleteHostTemplate(String clusterName, String hostTemplateName) throws ApiException {
        ApiResponse<ApiHostTemplate> resp = deleteHostTemplateWithHttpInfo(clusterName, hostTemplateName);
        return resp.getData();
    }

    /**
     * Deletes a host template.
     * Deletes a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to delete. (required)
     * @return ApiResponse&lt;ApiHostTemplate&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiHostTemplate> deleteHostTemplateWithHttpInfo(String clusterName, String hostTemplateName) throws ApiException {
        okhttp3.Call call = deleteHostTemplateValidateBeforeCall(clusterName, hostTemplateName, null, null);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Deletes a host template. (asynchronously)
     * Deletes a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to delete. (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 okhttp3.Call deleteHostTemplateAsync(String clusterName, String hostTemplateName, final ApiCallback<ApiHostTemplate> 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);
                }
            };
        }

        okhttp3.Call call = deleteHostTemplateValidateBeforeCall(clusterName, hostTemplateName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readHostTemplate
     * @param clusterName  (required)
     * @param hostTemplateName  (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 okhttp3.Call readHostTemplateCall(String clusterName, String hostTemplateName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates/{hostTemplateName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "hostTemplateName" + "\\}", apiClient.escapeString(hostTemplateName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = 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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call readHostTemplateValidateBeforeCall(String clusterName, String hostTemplateName, 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 readHostTemplate(Async)");
        }
        // verify the required parameter 'hostTemplateName' is set
        if (hostTemplateName == null) {
            throw new ApiException("Missing the required parameter 'hostTemplateName' when calling readHostTemplate(Async)");
        }

        okhttp3.Call call = readHostTemplateCall(clusterName, hostTemplateName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Retrieves information about a host template.
     * Retrieves information about a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName  (required)
     * @return ApiHostTemplate
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiHostTemplate readHostTemplate(String clusterName, String hostTemplateName) throws ApiException {
        ApiResponse<ApiHostTemplate> resp = readHostTemplateWithHttpInfo(clusterName, hostTemplateName);
        return resp.getData();
    }

    /**
     * Retrieves information about a host template.
     * Retrieves information about a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName  (required)
     * @return ApiResponse&lt;ApiHostTemplate&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiHostTemplate> readHostTemplateWithHttpInfo(String clusterName, String hostTemplateName) throws ApiException {
        okhttp3.Call call = readHostTemplateValidateBeforeCall(clusterName, hostTemplateName, null, null);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Retrieves information about a host template. (asynchronously)
     * Retrieves information about a host template. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName  (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 okhttp3.Call readHostTemplateAsync(String clusterName, String hostTemplateName, final ApiCallback<ApiHostTemplate> 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);
                }
            };
        }

        okhttp3.Call call = readHostTemplateValidateBeforeCall(clusterName, hostTemplateName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readHostTemplates
     * @param clusterName  (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 okhttp3.Call readHostTemplatesCall(String clusterName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = 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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call readHostTemplatesValidateBeforeCall(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 readHostTemplates(Async)");
        }

        okhttp3.Call call = readHostTemplatesCall(clusterName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Lists all host templates in a cluster.
     * Lists all host templates in a cluster. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @return ApiHostTemplateList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiHostTemplateList readHostTemplates(String clusterName) throws ApiException {
        ApiResponse<ApiHostTemplateList> resp = readHostTemplatesWithHttpInfo(clusterName);
        return resp.getData();
    }

    /**
     * Lists all host templates in a cluster.
     * Lists all host templates in a cluster. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @return ApiResponse&lt;ApiHostTemplateList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiHostTemplateList> readHostTemplatesWithHttpInfo(String clusterName) throws ApiException {
        okhttp3.Call call = readHostTemplatesValidateBeforeCall(clusterName, null, null);
        Type localVarReturnType = new TypeToken<ApiHostTemplateList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Lists all host templates in a cluster. (asynchronously)
     * Lists all host templates in a cluster. &lt;p&gt; Available since API v3.
     * @param clusterName  (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 okhttp3.Call readHostTemplatesAsync(String clusterName, final ApiCallback<ApiHostTemplateList> 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);
                }
            };
        }

        okhttp3.Call call = readHostTemplatesValidateBeforeCall(clusterName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiHostTemplateList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for reapplyHostTemplateOnHosts
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param deleteRoles Whether to delete roles on host if RCG is deleted from host template . (optional)
     * @param startRoles Whether to start the newly created roles or not. (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 okhttp3.Call reapplyHostTemplateOnHostsCall(String clusterName, String hostTemplateName, Boolean deleteRoles, Boolean startRoles, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates/{hostTemplateName}/commands/reapplyHostTemplateOnHosts"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "hostTemplateName" + "\\}", apiClient.escapeString(hostTemplateName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        if (deleteRoles != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("deleteRoles", deleteRoles));
        if (startRoles != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("startRoles", startRoles));

        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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call reapplyHostTemplateOnHostsValidateBeforeCall(String clusterName, String hostTemplateName, Boolean deleteRoles, Boolean startRoles, 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 reapplyHostTemplateOnHosts(Async)");
        }
        // verify the required parameter 'hostTemplateName' is set
        if (hostTemplateName == null) {
            throw new ApiException("Missing the required parameter 'hostTemplateName' when calling reapplyHostTemplateOnHosts(Async)");
        }

        okhttp3.Call call = reapplyHostTemplateOnHostsCall(clusterName, hostTemplateName, deleteRoles, startRoles, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Reapplies a host template on all the hosts associated with the host template.
     * Reapplies a host template on all the hosts associated with the host template. This will run apply host template command on the all the hosts using the host template  . &lt;p&gt; Set deleteRoles to true to delete the roles on the associated hosts if RCG is missing from host template. Check host tags with name as _cldr_cm_host_template_name to find out hosts using with the host template. &lt;p&gt; Available since API v46.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param deleteRoles Whether to delete roles on host if RCG is deleted from host template . (optional)
     * @param startRoles Whether to start the newly created roles or not. (optional)
     * @return ApiCommand
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCommand reapplyHostTemplateOnHosts(String clusterName, String hostTemplateName, Boolean deleteRoles, Boolean startRoles) throws ApiException {
        ApiResponse<ApiCommand> resp = reapplyHostTemplateOnHostsWithHttpInfo(clusterName, hostTemplateName, deleteRoles, startRoles);
        return resp.getData();
    }

    /**
     * Reapplies a host template on all the hosts associated with the host template.
     * Reapplies a host template on all the hosts associated with the host template. This will run apply host template command on the all the hosts using the host template  . &lt;p&gt; Set deleteRoles to true to delete the roles on the associated hosts if RCG is missing from host template. Check host tags with name as _cldr_cm_host_template_name to find out hosts using with the host template. &lt;p&gt; Available since API v46.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param deleteRoles Whether to delete roles on host if RCG is deleted from host template . (optional)
     * @param startRoles Whether to start the newly created roles or not. (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> reapplyHostTemplateOnHostsWithHttpInfo(String clusterName, String hostTemplateName, Boolean deleteRoles, Boolean startRoles) throws ApiException {
        okhttp3.Call call = reapplyHostTemplateOnHostsValidateBeforeCall(clusterName, hostTemplateName, deleteRoles, startRoles, null, null);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Reapplies a host template on all the hosts associated with the host template. (asynchronously)
     * Reapplies a host template on all the hosts associated with the host template. This will run apply host template command on the all the hosts using the host template  . &lt;p&gt; Set deleteRoles to true to delete the roles on the associated hosts if RCG is missing from host template. Check host tags with name as _cldr_cm_host_template_name to find out hosts using with the host template. &lt;p&gt; Available since API v46.
     * @param clusterName  (required)
     * @param hostTemplateName Host template to apply. (required)
     * @param deleteRoles Whether to delete roles on host if RCG is deleted from host template . (optional)
     * @param startRoles Whether to start the newly created roles or not. (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 okhttp3.Call reapplyHostTemplateOnHostsAsync(String clusterName, String hostTemplateName, Boolean deleteRoles, Boolean startRoles, 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);
                }
            };
        }

        okhttp3.Call call = reapplyHostTemplateOnHostsValidateBeforeCall(clusterName, hostTemplateName, deleteRoles, startRoles, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for updateHostTemplate
     * @param clusterName  (required)
     * @param hostTemplateName Host template with updated fields. (required)
     * @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 okhttp3.Call updateHostTemplateCall(String clusterName, String hostTemplateName, ApiHostTemplate body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;

        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/hostTemplates/{hostTemplateName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "hostTemplateName" + "\\}", apiClient.escapeString(hostTemplateName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = 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 okhttp3.Interceptor() {
                @Override
                public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
                    okhttp3.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, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call updateHostTemplateValidateBeforeCall(String clusterName, String hostTemplateName, ApiHostTemplate body, 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 updateHostTemplate(Async)");
        }
        // verify the required parameter 'hostTemplateName' is set
        if (hostTemplateName == null) {
            throw new ApiException("Missing the required parameter 'hostTemplateName' when calling updateHostTemplate(Async)");
        }

        okhttp3.Call call = updateHostTemplateCall(clusterName, hostTemplateName, body, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Updates an existing host template.
     * Updates an existing host template. &lt;p&gt; Can be used to update the role config groups in a host template or rename it. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template with updated fields. (required)
     * @param body  (optional)
     * @return ApiHostTemplate
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiHostTemplate updateHostTemplate(String clusterName, String hostTemplateName, ApiHostTemplate body) throws ApiException {
        ApiResponse<ApiHostTemplate> resp = updateHostTemplateWithHttpInfo(clusterName, hostTemplateName, body);
        return resp.getData();
    }

    /**
     * Updates an existing host template.
     * Updates an existing host template. &lt;p&gt; Can be used to update the role config groups in a host template or rename it. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template with updated fields. (required)
     * @param body  (optional)
     * @return ApiResponse&lt;ApiHostTemplate&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiHostTemplate> updateHostTemplateWithHttpInfo(String clusterName, String hostTemplateName, ApiHostTemplate body) throws ApiException {
        okhttp3.Call call = updateHostTemplateValidateBeforeCall(clusterName, hostTemplateName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Updates an existing host template. (asynchronously)
     * Updates an existing host template. &lt;p&gt; Can be used to update the role config groups in a host template or rename it. &lt;p&gt; Available since API v3.
     * @param clusterName  (required)
     * @param hostTemplateName Host template with updated fields. (required)
     * @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 okhttp3.Call updateHostTemplateAsync(String clusterName, String hostTemplateName, ApiHostTemplate body, final ApiCallback<ApiHostTemplate> 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);
                }
            };
        }

        okhttp3.Call call = updateHostTemplateValidateBeforeCall(clusterName, hostTemplateName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiHostTemplate>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
