/*
 * 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.ApiDashboard;
import com.cloudera.api.swagger.model.ApiDashboardList;

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

public class DashboardsResourceApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for createDashboards
     * @param body The list of dashboards 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 createDashboardsCall(ApiDashboardList body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/timeseries/dashboards";

        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 createDashboardsValidateBeforeCall(ApiDashboardList body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        
        com.squareup.okhttp.Call call = createDashboardsCall(body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Creates the list of dashboards.
     * Creates the list of dashboards. If any of the dashboards already exist this whole command will fail and no dashboards will be created. &lt;p&gt; Available since API v6.
     * @param body The list of dashboards to create. (optional)
     * @return ApiDashboardList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiDashboardList createDashboards(ApiDashboardList body) throws ApiException {
        ApiResponse<ApiDashboardList> resp = createDashboardsWithHttpInfo(body);
        return resp.getData();
    }

    /**
     * Creates the list of dashboards.
     * Creates the list of dashboards. If any of the dashboards already exist this whole command will fail and no dashboards will be created. &lt;p&gt; Available since API v6.
     * @param body The list of dashboards to create. (optional)
     * @return ApiResponse&lt;ApiDashboardList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiDashboardList> createDashboardsWithHttpInfo(ApiDashboardList body) throws ApiException {
        com.squareup.okhttp.Call call = createDashboardsValidateBeforeCall(body, null, null);
        Type localVarReturnType = new TypeToken<ApiDashboardList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Creates the list of dashboards. (asynchronously)
     * Creates the list of dashboards. If any of the dashboards already exist this whole command will fail and no dashboards will be created. &lt;p&gt; Available since API v6.
     * @param body The list of dashboards 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 createDashboardsAsync(ApiDashboardList body, final ApiCallback<ApiDashboardList> 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 = createDashboardsValidateBeforeCall(body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiDashboardList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for deleteDashboard
     * @param dashboardName The name of the dashboard. (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 deleteDashboardCall(String dashboardName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/timeseries/dashboards/{dashboardName}"
            .replaceAll("\\{" + "dashboardName" + "\\}", apiClient.escapeString(dashboardName.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 deleteDashboardValidateBeforeCall(String dashboardName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'dashboardName' is set
        if (dashboardName == null) {
            throw new ApiException("Missing the required parameter 'dashboardName' when calling deleteDashboard(Async)");
        }
        
        
        com.squareup.okhttp.Call call = deleteDashboardCall(dashboardName, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Deletes a dashboard.
     * Deletes a dashboard.  &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (required)
     * @return ApiDashboard
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiDashboard deleteDashboard(String dashboardName) throws ApiException {
        ApiResponse<ApiDashboard> resp = deleteDashboardWithHttpInfo(dashboardName);
        return resp.getData();
    }

    /**
     * Deletes a dashboard.
     * Deletes a dashboard.  &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (required)
     * @return ApiResponse&lt;ApiDashboard&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiDashboard> deleteDashboardWithHttpInfo(String dashboardName) throws ApiException {
        com.squareup.okhttp.Call call = deleteDashboardValidateBeforeCall(dashboardName, null, null);
        Type localVarReturnType = new TypeToken<ApiDashboard>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Deletes a dashboard. (asynchronously)
     * Deletes a dashboard.  &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (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 deleteDashboardAsync(String dashboardName, final ApiCallback<ApiDashboard> 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 = deleteDashboardValidateBeforeCall(dashboardName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiDashboard>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for getDashboard
     * @param dashboardName The name of the dashboard. (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 getDashboardCall(String dashboardName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/timeseries/dashboards/{dashboardName}"
            .replaceAll("\\{" + "dashboardName" + "\\}", apiClient.escapeString(dashboardName.toString()));

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

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

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

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

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

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

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

        
        
        
        
    }

    /**
     * Returns a dashboard definition for the specified name.
     * Returns a dashboard definition for the specified name. This dashboard can be imported with the createDashboards API. &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (required)
     * @return ApiDashboard
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiDashboard getDashboard(String dashboardName) throws ApiException {
        ApiResponse<ApiDashboard> resp = getDashboardWithHttpInfo(dashboardName);
        return resp.getData();
    }

    /**
     * Returns a dashboard definition for the specified name.
     * Returns a dashboard definition for the specified name. This dashboard can be imported with the createDashboards API. &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (required)
     * @return ApiResponse&lt;ApiDashboard&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiDashboard> getDashboardWithHttpInfo(String dashboardName) throws ApiException {
        com.squareup.okhttp.Call call = getDashboardValidateBeforeCall(dashboardName, null, null);
        Type localVarReturnType = new TypeToken<ApiDashboard>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Returns a dashboard definition for the specified name. (asynchronously)
     * Returns a dashboard definition for the specified name. This dashboard can be imported with the createDashboards API. &lt;p&gt; Available since API v6.
     * @param dashboardName The name of the dashboard. (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 getDashboardAsync(String dashboardName, final ApiCallback<ApiDashboard> 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 = getDashboardValidateBeforeCall(dashboardName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiDashboard>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for getDashboards
     * @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 getDashboardsCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/timeseries/dashboards";

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

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

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

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

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

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

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

        
        
        
        
    }

    /**
     * Returns the list of all user-customized dashboards.
     * Returns the list of all user-customized dashboards. This includes both the new dashboards created by users as well as any user customizations to built-in dashboards. &lt;p&gt; Available since API v6.
     * @return ApiDashboardList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiDashboardList getDashboards() throws ApiException {
        ApiResponse<ApiDashboardList> resp = getDashboardsWithHttpInfo();
        return resp.getData();
    }

    /**
     * Returns the list of all user-customized dashboards.
     * Returns the list of all user-customized dashboards. This includes both the new dashboards created by users as well as any user customizations to built-in dashboards. &lt;p&gt; Available since API v6.
     * @return ApiResponse&lt;ApiDashboardList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiDashboardList> getDashboardsWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getDashboardsValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<ApiDashboardList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Returns the list of all user-customized dashboards. (asynchronously)
     * Returns the list of all user-customized dashboards. This includes both the new dashboards created by users as well as any user customizations to built-in dashboards. &lt;p&gt; Available since API v6.
     * @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 getDashboardsAsync(final ApiCallback<ApiDashboardList> 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 = getDashboardsValidateBeforeCall(progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiDashboardList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
