/*
 * 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.ApiTagToEntitiesList;

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

public class TagsResourceApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for getTags
     * @param limit Number of tags to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @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 getTagsCall(java.math.BigDecimal limit, java.math.BigDecimal offset, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/tags";

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

        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 getTagsValidateBeforeCall(java.math.BigDecimal limit, java.math.BigDecimal offset, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {

        okhttp3.Call call = getTagsCall(limit, offset, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Current CM entities and their tags.
     * Current CM entities and their tags. Tag names beginning with the prefix &lt;code&gt;_cldr_&lt;/code&gt; (case insensitive) are reserved for internal use by Cloudera.
     * @param limit Number of tags to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @return ApiTagToEntitiesList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiTagToEntitiesList getTags(java.math.BigDecimal limit, java.math.BigDecimal offset) throws ApiException {
        ApiResponse<ApiTagToEntitiesList> resp = getTagsWithHttpInfo(limit, offset);
        return resp.getData();
    }

    /**
     * Current CM entities and their tags.
     * Current CM entities and their tags. Tag names beginning with the prefix &lt;code&gt;_cldr_&lt;/code&gt; (case insensitive) are reserved for internal use by Cloudera.
     * @param limit Number of tags to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @return ApiResponse&lt;ApiTagToEntitiesList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiTagToEntitiesList> getTagsWithHttpInfo(java.math.BigDecimal limit, java.math.BigDecimal offset) throws ApiException {
        okhttp3.Call call = getTagsValidateBeforeCall(limit, offset, null, null);
        Type localVarReturnType = new TypeToken<ApiTagToEntitiesList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Current CM entities and their tags. (asynchronously)
     * Current CM entities and their tags. Tag names beginning with the prefix &lt;code&gt;_cldr_&lt;/code&gt; (case insensitive) are reserved for internal use by Cloudera.
     * @param limit Number of tags to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @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 getTagsAsync(java.math.BigDecimal limit, java.math.BigDecimal offset, final ApiCallback<ApiTagToEntitiesList> 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 = getTagsValidateBeforeCall(limit, offset, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiTagToEntitiesList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readTagsByName
     * @param tagName Name of the tag (required)
     * @param limit Number of entries to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @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 readTagsByNameCall(String tagName, java.math.BigDecimal limit, java.math.BigDecimal offset, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

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

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

        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 readTagsByNameValidateBeforeCall(String tagName, java.math.BigDecimal limit, java.math.BigDecimal offset, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        // verify the required parameter 'tagName' is set
        if (tagName == null) {
            throw new ApiException("Missing the required parameter 'tagName' when calling readTagsByName(Async)");
        }

        okhttp3.Call call = readTagsByNameCall(tagName, limit, offset, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get Entities given the Tag name, grouped by entity type.
     * Get Entities given the Tag name, grouped by entity type.
     * @param tagName Name of the tag (required)
     * @param limit Number of entries to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @return ApiTagToEntitiesList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiTagToEntitiesList readTagsByName(String tagName, java.math.BigDecimal limit, java.math.BigDecimal offset) throws ApiException {
        ApiResponse<ApiTagToEntitiesList> resp = readTagsByNameWithHttpInfo(tagName, limit, offset);
        return resp.getData();
    }

    /**
     * Get Entities given the Tag name, grouped by entity type.
     * Get Entities given the Tag name, grouped by entity type.
     * @param tagName Name of the tag (required)
     * @param limit Number of entries to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @return ApiResponse&lt;ApiTagToEntitiesList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiTagToEntitiesList> readTagsByNameWithHttpInfo(String tagName, java.math.BigDecimal limit, java.math.BigDecimal offset) throws ApiException {
        okhttp3.Call call = readTagsByNameValidateBeforeCall(tagName, limit, offset, null, null);
        Type localVarReturnType = new TypeToken<ApiTagToEntitiesList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get Entities given the Tag name, grouped by entity type. (asynchronously)
     * Get Entities given the Tag name, grouped by entity type.
     * @param tagName Name of the tag (required)
     * @param limit Number of entries to search for. Maximum value for limit is 1000. (optional, default to 10)
     * @param offset Starting index of the list (optional, default to 0)
     * @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 readTagsByNameAsync(String tagName, java.math.BigDecimal limit, java.math.BigDecimal offset, final ApiCallback<ApiTagToEntitiesList> 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 = readTagsByNameValidateBeforeCall(tagName, limit, offset, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiTagToEntitiesList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
