/*
 * 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.ApiAdhocSnapshot;
import com.cloudera.api.swagger.model.ApiCommand;
import com.cloudera.api.swagger.model.ApiSnapshotCommandList;
import com.cloudera.api.swagger.model.ApiSnapshotPolicy;
import com.cloudera.api.swagger.model.ApiSnapshotPolicyList;

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

public class SnapshotsResourceApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for adhocSnapshot
     * @param clusterName  (required)
     * @param serviceName  (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 com.squareup.okhttp.Call adhocSnapshotCall(String clusterName, String serviceName, ApiAdhocSnapshot body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.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 = {
            "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 adhocSnapshotValidateBeforeCall(String clusterName, String serviceName, ApiAdhocSnapshot 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 adhocSnapshot(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling adhocSnapshot(Async)");
        }
        
        
        com.squareup.okhttp.Call call = adhocSnapshotCall(clusterName, serviceName, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Creates one or more snapshot policies.
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @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 adhocSnapshot(String clusterName, String serviceName, ApiAdhocSnapshot body) throws ApiException {
        ApiResponse<ApiCommand> resp = adhocSnapshotWithHttpInfo(clusterName, serviceName, body);
        return resp.getData();
    }

    /**
     * Creates one or more snapshot policies.
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @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> adhocSnapshotWithHttpInfo(String clusterName, String serviceName, ApiAdhocSnapshot body) throws ApiException {
        com.squareup.okhttp.Call call = adhocSnapshotValidateBeforeCall(clusterName, serviceName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Creates one or more snapshot policies. (asynchronously)
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (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 com.squareup.okhttp.Call adhocSnapshotAsync(String clusterName, String serviceName, ApiAdhocSnapshot 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 = adhocSnapshotValidateBeforeCall(clusterName, serviceName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for createPolicies
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param body List of the snapshot policies 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 com.squareup.okhttp.Call createPoliciesCall(String clusterName, String serviceName, ApiSnapshotPolicyList body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.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 = {
            "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 createPoliciesValidateBeforeCall(String clusterName, String serviceName, ApiSnapshotPolicyList 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 createPolicies(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling createPolicies(Async)");
        }
        
        
        com.squareup.okhttp.Call call = createPoliciesCall(clusterName, serviceName, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Creates one or more snapshot policies.
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param body List of the snapshot policies to create. (optional)
     * @return ApiSnapshotPolicyList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotPolicyList createPolicies(String clusterName, String serviceName, ApiSnapshotPolicyList body) throws ApiException {
        ApiResponse<ApiSnapshotPolicyList> resp = createPoliciesWithHttpInfo(clusterName, serviceName, body);
        return resp.getData();
    }

    /**
     * Creates one or more snapshot policies.
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param body List of the snapshot policies to create. (optional)
     * @return ApiResponse&lt;ApiSnapshotPolicyList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotPolicyList> createPoliciesWithHttpInfo(String clusterName, String serviceName, ApiSnapshotPolicyList body) throws ApiException {
        com.squareup.okhttp.Call call = createPoliciesValidateBeforeCall(clusterName, serviceName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicyList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Creates one or more snapshot policies. (asynchronously)
     * Creates one or more snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param body List of the snapshot policies 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 com.squareup.okhttp.Call createPoliciesAsync(String clusterName, String serviceName, ApiSnapshotPolicyList body, final ApiCallback<ApiSnapshotPolicyList> 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 = createPoliciesValidateBeforeCall(clusterName, serviceName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicyList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for deletePolicy
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (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 deletePolicyCall(String clusterName, String policyName, String serviceName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies/{policyName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "policyName" + "\\}", apiClient.escapeString(policyName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.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, "DELETE", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call deletePolicyValidateBeforeCall(String clusterName, String policyName, String serviceName, 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 deletePolicy(Async)");
        }
        
        // verify the required parameter 'policyName' is set
        if (policyName == null) {
            throw new ApiException("Missing the required parameter 'policyName' when calling deletePolicy(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling deletePolicy(Async)");
        }
        
        
        com.squareup.okhttp.Call call = deletePolicyCall(clusterName, policyName, serviceName, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Deletes an existing snapshot policy.
     * Deletes an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @return ApiSnapshotPolicy
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotPolicy deletePolicy(String clusterName, String policyName, String serviceName) throws ApiException {
        ApiResponse<ApiSnapshotPolicy> resp = deletePolicyWithHttpInfo(clusterName, policyName, serviceName);
        return resp.getData();
    }

    /**
     * Deletes an existing snapshot policy.
     * Deletes an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @return ApiResponse&lt;ApiSnapshotPolicy&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotPolicy> deletePolicyWithHttpInfo(String clusterName, String policyName, String serviceName) throws ApiException {
        com.squareup.okhttp.Call call = deletePolicyValidateBeforeCall(clusterName, policyName, serviceName, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Deletes an existing snapshot policy. (asynchronously)
     * Deletes an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (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 deletePolicyAsync(String clusterName, String policyName, String serviceName, final ApiCallback<ApiSnapshotPolicy> 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 = deletePolicyValidateBeforeCall(clusterName, policyName, serviceName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readHistory
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param limit Maximum number of commands to retrieve. (optional, default to 20)
     * @param offset Index of first command to retrieve. (optional, default to 0)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readHistoryCall(String clusterName, String policyName, String serviceName, java.math.BigDecimal limit, java.math.BigDecimal offset, String view, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies/{policyName}/history"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "policyName" + "\\}", apiClient.escapeString(policyName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.toString()));

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

        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 readHistoryValidateBeforeCall(String clusterName, String policyName, String serviceName, java.math.BigDecimal limit, java.math.BigDecimal offset, String view, 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 readHistory(Async)");
        }
        
        // verify the required parameter 'policyName' is set
        if (policyName == null) {
            throw new ApiException("Missing the required parameter 'policyName' when calling readHistory(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling readHistory(Async)");
        }
        
        
        com.squareup.okhttp.Call call = readHistoryCall(clusterName, policyName, serviceName, limit, offset, view, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Returns a list of commands triggered by a snapshot policy.
     * Returns a list of commands triggered by a snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param limit Maximum number of commands to retrieve. (optional, default to 20)
     * @param offset Index of first command to retrieve. (optional, default to 0)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiSnapshotCommandList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotCommandList readHistory(String clusterName, String policyName, String serviceName, java.math.BigDecimal limit, java.math.BigDecimal offset, String view) throws ApiException {
        ApiResponse<ApiSnapshotCommandList> resp = readHistoryWithHttpInfo(clusterName, policyName, serviceName, limit, offset, view);
        return resp.getData();
    }

    /**
     * Returns a list of commands triggered by a snapshot policy.
     * Returns a list of commands triggered by a snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param limit Maximum number of commands to retrieve. (optional, default to 20)
     * @param offset Index of first command to retrieve. (optional, default to 0)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiResponse&lt;ApiSnapshotCommandList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotCommandList> readHistoryWithHttpInfo(String clusterName, String policyName, String serviceName, java.math.BigDecimal limit, java.math.BigDecimal offset, String view) throws ApiException {
        com.squareup.okhttp.Call call = readHistoryValidateBeforeCall(clusterName, policyName, serviceName, limit, offset, view, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotCommandList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Returns a list of commands triggered by a snapshot policy. (asynchronously)
     * Returns a list of commands triggered by a snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param limit Maximum number of commands to retrieve. (optional, default to 20)
     * @param offset Index of first command to retrieve. (optional, default to 0)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readHistoryAsync(String clusterName, String policyName, String serviceName, java.math.BigDecimal limit, java.math.BigDecimal offset, String view, final ApiCallback<ApiSnapshotCommandList> 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 = readHistoryValidateBeforeCall(clusterName, policyName, serviceName, limit, offset, view, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotCommandList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readPolicies
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readPoliciesCall(String clusterName, String serviceName, String view, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.toString()));

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

        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 readPoliciesValidateBeforeCall(String clusterName, String serviceName, String view, 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 readPolicies(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling readPolicies(Async)");
        }
        
        
        com.squareup.okhttp.Call call = readPoliciesCall(clusterName, serviceName, view, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Returns information for all snapshot policies.
     * Returns information for all snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiSnapshotPolicyList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotPolicyList readPolicies(String clusterName, String serviceName, String view) throws ApiException {
        ApiResponse<ApiSnapshotPolicyList> resp = readPoliciesWithHttpInfo(clusterName, serviceName, view);
        return resp.getData();
    }

    /**
     * Returns information for all snapshot policies.
     * Returns information for all snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiResponse&lt;ApiSnapshotPolicyList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotPolicyList> readPoliciesWithHttpInfo(String clusterName, String serviceName, String view) throws ApiException {
        com.squareup.okhttp.Call call = readPoliciesValidateBeforeCall(clusterName, serviceName, view, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicyList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Returns information for all snapshot policies. (asynchronously)
     * Returns information for all snapshot policies.
     * @param clusterName  (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readPoliciesAsync(String clusterName, String serviceName, String view, final ApiCallback<ApiSnapshotPolicyList> 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 = readPoliciesValidateBeforeCall(clusterName, serviceName, view, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicyList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readPolicy
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readPolicyCall(String clusterName, String policyName, String serviceName, String view, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies/{policyName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "policyName" + "\\}", apiClient.escapeString(policyName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.toString()));

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

        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 readPolicyValidateBeforeCall(String clusterName, String policyName, String serviceName, String view, 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 readPolicy(Async)");
        }
        
        // verify the required parameter 'policyName' is set
        if (policyName == null) {
            throw new ApiException("Missing the required parameter 'policyName' when calling readPolicy(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling readPolicy(Async)");
        }
        
        
        com.squareup.okhttp.Call call = readPolicyCall(clusterName, policyName, serviceName, view, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Returns information for a specific snapshot policy.
     * Returns information for a specific snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiSnapshotPolicy
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotPolicy readPolicy(String clusterName, String policyName, String serviceName, String view) throws ApiException {
        ApiResponse<ApiSnapshotPolicy> resp = readPolicyWithHttpInfo(clusterName, policyName, serviceName, view);
        return resp.getData();
    }

    /**
     * Returns information for a specific snapshot policy.
     * Returns information for a specific snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @return ApiResponse&lt;ApiSnapshotPolicy&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotPolicy> readPolicyWithHttpInfo(String clusterName, String policyName, String serviceName, String view) throws ApiException {
        com.squareup.okhttp.Call call = readPolicyValidateBeforeCall(clusterName, policyName, serviceName, view, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Returns information for a specific snapshot policy. (asynchronously)
     * Returns information for a specific snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param view The view to materialize. (optional, default to summary)
     * @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 readPolicyAsync(String clusterName, String policyName, String serviceName, String view, final ApiCallback<ApiSnapshotPolicy> 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 = readPolicyValidateBeforeCall(clusterName, policyName, serviceName, view, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for updatePolicy
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param body Modified policy. (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 updatePolicyCall(String clusterName, String policyName, String serviceName, ApiSnapshotPolicy body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/clusters/{clusterName}/services/{serviceName}/snapshots/policies/{policyName}"
            .replaceAll("\\{" + "clusterName" + "\\}", apiClient.escapeString(clusterName.toString()))
            .replaceAll("\\{" + "policyName" + "\\}", apiClient.escapeString(policyName.toString()))
            .replaceAll("\\{" + "serviceName" + "\\}", apiClient.escapeString(serviceName.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 = {
            "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, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call updatePolicyValidateBeforeCall(String clusterName, String policyName, String serviceName, ApiSnapshotPolicy 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 updatePolicy(Async)");
        }
        
        // verify the required parameter 'policyName' is set
        if (policyName == null) {
            throw new ApiException("Missing the required parameter 'policyName' when calling updatePolicy(Async)");
        }
        
        // verify the required parameter 'serviceName' is set
        if (serviceName == null) {
            throw new ApiException("Missing the required parameter 'serviceName' when calling updatePolicy(Async)");
        }
        
        
        com.squareup.okhttp.Call call = updatePolicyCall(clusterName, policyName, serviceName, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Updates an existing snapshot policy.
     * Updates an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param body Modified policy. (optional)
     * @return ApiSnapshotPolicy
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiSnapshotPolicy updatePolicy(String clusterName, String policyName, String serviceName, ApiSnapshotPolicy body) throws ApiException {
        ApiResponse<ApiSnapshotPolicy> resp = updatePolicyWithHttpInfo(clusterName, policyName, serviceName, body);
        return resp.getData();
    }

    /**
     * Updates an existing snapshot policy.
     * Updates an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param body Modified policy. (optional)
     * @return ApiResponse&lt;ApiSnapshotPolicy&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiSnapshotPolicy> updatePolicyWithHttpInfo(String clusterName, String policyName, String serviceName, ApiSnapshotPolicy body) throws ApiException {
        com.squareup.okhttp.Call call = updatePolicyValidateBeforeCall(clusterName, policyName, serviceName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Updates an existing snapshot policy. (asynchronously)
     * Updates an existing snapshot policy.
     * @param clusterName  (required)
     * @param policyName Name of an existing snapshot policy. (required)
     * @param serviceName  (required)
     * @param body Modified policy. (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 updatePolicyAsync(String clusterName, String policyName, String serviceName, ApiSnapshotPolicy body, final ApiCallback<ApiSnapshotPolicy> 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 = updatePolicyValidateBeforeCall(clusterName, policyName, serviceName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiSnapshotPolicy>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
