/*
 * Internal Utility API
 * This API allows you to access internal data.
 *
 * OpenAPI spec version: 1.0.0
 * 
 *
 * 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 org.wso2.am.integration.clients.internal.api;

import org.wso2.am.integration.clients.internal.ApiCallback;
import org.wso2.am.integration.clients.internal.ApiClient;
import org.wso2.am.integration.clients.internal.ApiException;
import org.wso2.am.integration.clients.internal.ApiResponse;
import org.wso2.am.integration.clients.internal.Configuration;
import org.wso2.am.integration.clients.internal.Pair;
import org.wso2.am.integration.clients.internal.ProgressRequestBody;
import org.wso2.am.integration.clients.internal.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import org.wso2.am.integration.clients.internal.api.dto.APIListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ApiPolicyListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ApplicationKeyMappingListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ApplicationListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ApplicationPolicyListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ErrorDTO;
import org.wso2.am.integration.clients.internal.api.dto.GlobalPolicyListDTO;
import org.wso2.am.integration.clients.internal.api.dto.ScopesListDTO;
import org.wso2.am.integration.clients.internal.api.dto.SubscriptionListDTO;
import org.wso2.am.integration.clients.internal.api.dto.SubscriptionPolicyListDTO;

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

public class SubscriptionValidationApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for apiPoliciesGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Api policy name  (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 apiPoliciesGetCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/api-policies";

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call apiPoliciesGetValidateBeforeCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling apiPoliciesGet(Async)");
        }
        

        com.squareup.okhttp.Call call = apiPoliciesGetCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all API throttling policies
     * This will provide access to api level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Api policy name  (optional)
     * @return ApiPolicyListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiPolicyListDTO apiPoliciesGet(String xWSO2Tenant, String policyName) throws ApiException {
        ApiResponse<ApiPolicyListDTO> resp = apiPoliciesGetWithHttpInfo(xWSO2Tenant, policyName);
        return resp.getData();
    }

    /**
     * Get all API throttling policies
     * This will provide access to api level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Api policy name  (optional)
     * @return ApiResponse&lt;ApiPolicyListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiPolicyListDTO> apiPoliciesGetWithHttpInfo(String xWSO2Tenant, String policyName) throws ApiException {
        com.squareup.okhttp.Call call = apiPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, null, null);
        Type localVarReturnType = new TypeToken<ApiPolicyListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all API throttling policies (asynchronously)
     * This will provide access to api level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Api policy name  (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 apiPoliciesGetAsync(String xWSO2Tenant, String policyName, final ApiCallback<ApiPolicyListDTO> 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 = apiPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiPolicyListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for apisGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  (optional)
     * @param context **Search condition**.  context of the api  (optional)
     * @param version **Search condition**.  versio  of the api  (optional)
     * @param gatewayLabel **Search condition**.  label associated with the APIs  (optional)
     * @param accept Media types acceptable for the response. Default is application/json.  (optional, default to application/json)
     * @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 apisGetCall(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

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

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        if (apiId != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("apiId", apiId));
        if (context != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("context", context));
        if (version != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("version", version));
        if (gatewayLabel != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("gatewayLabel", gatewayLabel));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));
        if (accept != null)
        localVarHeaderParams.put("Accept", apiClient.parameterToString(accept));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call apisGetValidateBeforeCall(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling apisGet(Async)");
        }
        

        com.squareup.okhttp.Call call = apisGetCall(xWSO2Tenant, apiId, context, version, gatewayLabel, accept, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all apis
     * This will provide access to apis in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  (optional)
     * @param context **Search condition**.  context of the api  (optional)
     * @param version **Search condition**.  versio  of the api  (optional)
     * @param gatewayLabel **Search condition**.  label associated with the APIs  (optional)
     * @param accept Media types acceptable for the response. Default is application/json.  (optional, default to application/json)
     * @return APIListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public APIListDTO apisGet(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept) throws ApiException {
        ApiResponse<APIListDTO> resp = apisGetWithHttpInfo(xWSO2Tenant, apiId, context, version, gatewayLabel, accept);
        return resp.getData();
    }

    /**
     * Get all apis
     * This will provide access to apis in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  (optional)
     * @param context **Search condition**.  context of the api  (optional)
     * @param version **Search condition**.  versio  of the api  (optional)
     * @param gatewayLabel **Search condition**.  label associated with the APIs  (optional)
     * @param accept Media types acceptable for the response. Default is application/json.  (optional, default to application/json)
     * @return ApiResponse&lt;APIListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<APIListDTO> apisGetWithHttpInfo(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept) throws ApiException {
        com.squareup.okhttp.Call call = apisGetValidateBeforeCall(xWSO2Tenant, apiId, context, version, gatewayLabel, accept, null, null);
        Type localVarReturnType = new TypeToken<APIListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all apis (asynchronously)
     * This will provide access to apis in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  (optional)
     * @param context **Search condition**.  context of the api  (optional)
     * @param version **Search condition**.  versio  of the api  (optional)
     * @param gatewayLabel **Search condition**.  label associated with the APIs  (optional)
     * @param accept Media types acceptable for the response. Default is application/json.  (optional, default to application/json)
     * @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 apisGetAsync(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept, final ApiCallback<APIListDTO> 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 = apisGetValidateBeforeCall(xWSO2Tenant, apiId, context, version, gatewayLabel, accept, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<APIListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for applicationKeyMappingsGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param consumerKey **Search condition**.  Consumer Key of the application  (optional)
     * @param keymanager **Search condition**.  KeyManager associated to consumer_key of the application  (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 applicationKeyMappingsGetCall(String xWSO2Tenant, String consumerKey, String keymanager, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/application-key-mappings";

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call applicationKeyMappingsGetValidateBeforeCall(String xWSO2Tenant, String consumerKey, String keymanager, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling applicationKeyMappingsGet(Async)");
        }
        

        com.squareup.okhttp.Call call = applicationKeyMappingsGetCall(xWSO2Tenant, consumerKey, keymanager, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all application key mappings
     * This will provide access to application vs key mappings in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param consumerKey **Search condition**.  Consumer Key of the application  (optional)
     * @param keymanager **Search condition**.  KeyManager associated to consumer_key of the application  (optional)
     * @return ApplicationKeyMappingListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApplicationKeyMappingListDTO applicationKeyMappingsGet(String xWSO2Tenant, String consumerKey, String keymanager) throws ApiException {
        ApiResponse<ApplicationKeyMappingListDTO> resp = applicationKeyMappingsGetWithHttpInfo(xWSO2Tenant, consumerKey, keymanager);
        return resp.getData();
    }

    /**
     * Get all application key mappings
     * This will provide access to application vs key mappings in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param consumerKey **Search condition**.  Consumer Key of the application  (optional)
     * @param keymanager **Search condition**.  KeyManager associated to consumer_key of the application  (optional)
     * @return ApiResponse&lt;ApplicationKeyMappingListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApplicationKeyMappingListDTO> applicationKeyMappingsGetWithHttpInfo(String xWSO2Tenant, String consumerKey, String keymanager) throws ApiException {
        com.squareup.okhttp.Call call = applicationKeyMappingsGetValidateBeforeCall(xWSO2Tenant, consumerKey, keymanager, null, null);
        Type localVarReturnType = new TypeToken<ApplicationKeyMappingListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all application key mappings (asynchronously)
     * This will provide access to application vs key mappings in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param consumerKey **Search condition**.  Consumer Key of the application  (optional)
     * @param keymanager **Search condition**.  KeyManager associated to consumer_key of the application  (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 applicationKeyMappingsGetAsync(String xWSO2Tenant, String consumerKey, String keymanager, final ApiCallback<ApplicationKeyMappingListDTO> 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 = applicationKeyMappingsGetValidateBeforeCall(xWSO2Tenant, consumerKey, keymanager, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApplicationKeyMappingListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for applicationPoliciesGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Application policy name  (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 applicationPoliciesGetCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/application-policies";

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call applicationPoliciesGetValidateBeforeCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling applicationPoliciesGet(Async)");
        }
        

        com.squareup.okhttp.Call call = applicationPoliciesGetCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all application throttling policies
     * This will provide access to application level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Application policy name  (optional)
     * @return ApplicationPolicyListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApplicationPolicyListDTO applicationPoliciesGet(String xWSO2Tenant, String policyName) throws ApiException {
        ApiResponse<ApplicationPolicyListDTO> resp = applicationPoliciesGetWithHttpInfo(xWSO2Tenant, policyName);
        return resp.getData();
    }

    /**
     * Get all application throttling policies
     * This will provide access to application level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Application policy name  (optional)
     * @return ApiResponse&lt;ApplicationPolicyListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApplicationPolicyListDTO> applicationPoliciesGetWithHttpInfo(String xWSO2Tenant, String policyName) throws ApiException {
        com.squareup.okhttp.Call call = applicationPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, null, null);
        Type localVarReturnType = new TypeToken<ApplicationPolicyListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all application throttling policies (asynchronously)
     * This will provide access to application level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Application policy name  (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 applicationPoliciesGetAsync(String xWSO2Tenant, String policyName, final ApiCallback<ApplicationPolicyListDTO> 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 = applicationPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApplicationPolicyListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for applicationsGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param appId **Search condition**.  Application ID of the application  (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 applicationsGetCall(String xWSO2Tenant, Integer appId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

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

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call applicationsGetValidateBeforeCall(String xWSO2Tenant, Integer appId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling applicationsGet(Async)");
        }
        

        com.squareup.okhttp.Call call = applicationsGetCall(xWSO2Tenant, appId, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all applications
     * This will provide access to applications in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param appId **Search condition**.  Application ID of the application  (optional)
     * @return ApplicationListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApplicationListDTO applicationsGet(String xWSO2Tenant, Integer appId) throws ApiException {
        ApiResponse<ApplicationListDTO> resp = applicationsGetWithHttpInfo(xWSO2Tenant, appId);
        return resp.getData();
    }

    /**
     * Get all applications
     * This will provide access to applications in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param appId **Search condition**.  Application ID of the application  (optional)
     * @return ApiResponse&lt;ApplicationListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApplicationListDTO> applicationsGetWithHttpInfo(String xWSO2Tenant, Integer appId) throws ApiException {
        com.squareup.okhttp.Call call = applicationsGetValidateBeforeCall(xWSO2Tenant, appId, null, null);
        Type localVarReturnType = new TypeToken<ApplicationListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all applications (asynchronously)
     * This will provide access to applications in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param appId **Search condition**.  Application ID of the application  (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 applicationsGetAsync(String xWSO2Tenant, Integer appId, final ApiCallback<ApplicationListDTO> 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 = applicationsGetValidateBeforeCall(xWSO2Tenant, appId, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApplicationListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for globalPoliciesGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Global policy name  (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 globalPoliciesGetCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/global-policies";

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call globalPoliciesGetValidateBeforeCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling globalPoliciesGet(Async)");
        }
        

        com.squareup.okhttp.Call call = globalPoliciesGetCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all Global throttling policies
     * This will provide access to global throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Global policy name  (optional)
     * @return GlobalPolicyListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public GlobalPolicyListDTO globalPoliciesGet(String xWSO2Tenant, String policyName) throws ApiException {
        ApiResponse<GlobalPolicyListDTO> resp = globalPoliciesGetWithHttpInfo(xWSO2Tenant, policyName);
        return resp.getData();
    }

    /**
     * Get all Global throttling policies
     * This will provide access to global throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Global policy name  (optional)
     * @return ApiResponse&lt;GlobalPolicyListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<GlobalPolicyListDTO> globalPoliciesGetWithHttpInfo(String xWSO2Tenant, String policyName) throws ApiException {
        com.squareup.okhttp.Call call = globalPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, null, null);
        Type localVarReturnType = new TypeToken<GlobalPolicyListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all Global throttling policies (asynchronously)
     * This will provide access to global throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Global policy name  (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 globalPoliciesGetAsync(String xWSO2Tenant, String policyName, final ApiCallback<GlobalPolicyListDTO> 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 = globalPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<GlobalPolicyListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for scopesGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param scopeKey **Search condition**.  Scope Key  (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 scopesGetCall(String xWSO2Tenant, String scopeKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

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

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call scopesGetValidateBeforeCall(String xWSO2Tenant, String scopeKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling scopesGet(Async)");
        }
        

        com.squareup.okhttp.Call call = scopesGetCall(xWSO2Tenant, scopeKey, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all scopes.
     * This will provide access to the Scopes created in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param scopeKey **Search condition**.  Scope Key  (optional)
     * @return ScopesListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ScopesListDTO scopesGet(String xWSO2Tenant, String scopeKey) throws ApiException {
        ApiResponse<ScopesListDTO> resp = scopesGetWithHttpInfo(xWSO2Tenant, scopeKey);
        return resp.getData();
    }

    /**
     * Get all scopes.
     * This will provide access to the Scopes created in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param scopeKey **Search condition**.  Scope Key  (optional)
     * @return ApiResponse&lt;ScopesListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ScopesListDTO> scopesGetWithHttpInfo(String xWSO2Tenant, String scopeKey) throws ApiException {
        com.squareup.okhttp.Call call = scopesGetValidateBeforeCall(xWSO2Tenant, scopeKey, null, null);
        Type localVarReturnType = new TypeToken<ScopesListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all scopes. (asynchronously)
     * This will provide access to the Scopes created in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param scopeKey **Search condition**.  Scope Key  (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 scopesGetAsync(String xWSO2Tenant, String scopeKey, final ApiCallback<ScopesListDTO> 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 = scopesGetValidateBeforeCall(xWSO2Tenant, scopeKey, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ScopesListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for subscriptionPoliciesGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Subscription policy name  (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 subscriptionPoliciesGetCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/subscription-policies";

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call subscriptionPoliciesGetValidateBeforeCall(String xWSO2Tenant, String policyName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling subscriptionPoliciesGet(Async)");
        }
        

        com.squareup.okhttp.Call call = subscriptionPoliciesGetCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all subscription throttling policies
     * This will provide access to subscription level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Subscription policy name  (optional)
     * @return SubscriptionPolicyListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public SubscriptionPolicyListDTO subscriptionPoliciesGet(String xWSO2Tenant, String policyName) throws ApiException {
        ApiResponse<SubscriptionPolicyListDTO> resp = subscriptionPoliciesGetWithHttpInfo(xWSO2Tenant, policyName);
        return resp.getData();
    }

    /**
     * Get all subscription throttling policies
     * This will provide access to subscription level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Subscription policy name  (optional)
     * @return ApiResponse&lt;SubscriptionPolicyListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<SubscriptionPolicyListDTO> subscriptionPoliciesGetWithHttpInfo(String xWSO2Tenant, String policyName) throws ApiException {
        com.squareup.okhttp.Call call = subscriptionPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, null, null);
        Type localVarReturnType = new TypeToken<SubscriptionPolicyListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all subscription throttling policies (asynchronously)
     * This will provide access to subscription level throttling policies in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param policyName **Search condition**.  Subscription policy name  (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 subscriptionPoliciesGetAsync(String xWSO2Tenant, String policyName, final ApiCallback<SubscriptionPolicyListDTO> 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 = subscriptionPoliciesGetValidateBeforeCall(xWSO2Tenant, policyName, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<SubscriptionPolicyListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for subscriptionsGet
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  of the subscription  (optional)
     * @param appId **Search condition**.   Application ID  of the subscription  (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 subscriptionsGetCall(String xWSO2Tenant, Integer apiId, Integer appId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

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

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

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (xWSO2Tenant != null)
        localVarHeaderParams.put("xWSO2Tenant", apiClient.parameterToString(xWSO2Tenant));

        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[] {  };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call subscriptionsGetValidateBeforeCall(String xWSO2Tenant, Integer apiId, Integer appId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'xWSO2Tenant' is set
        if (xWSO2Tenant == null) {
            throw new ApiException("Missing the required parameter 'xWSO2Tenant' when calling subscriptionsGet(Async)");
        }
        

        com.squareup.okhttp.Call call = subscriptionsGetCall(xWSO2Tenant, apiId, appId, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all subscriptions
     * This will provide access to subscriptions in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  of the subscription  (optional)
     * @param appId **Search condition**.   Application ID  of the subscription  (optional)
     * @return SubscriptionListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public SubscriptionListDTO subscriptionsGet(String xWSO2Tenant, Integer apiId, Integer appId) throws ApiException {
        ApiResponse<SubscriptionListDTO> resp = subscriptionsGetWithHttpInfo(xWSO2Tenant, apiId, appId);
        return resp.getData();
    }

    /**
     * Get all subscriptions
     * This will provide access to subscriptions in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  of the subscription  (optional)
     * @param appId **Search condition**.   Application ID  of the subscription  (optional)
     * @return ApiResponse&lt;SubscriptionListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<SubscriptionListDTO> subscriptionsGetWithHttpInfo(String xWSO2Tenant, Integer apiId, Integer appId) throws ApiException {
        com.squareup.okhttp.Call call = subscriptionsGetValidateBeforeCall(xWSO2Tenant, apiId, appId, null, null);
        Type localVarReturnType = new TypeToken<SubscriptionListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all subscriptions (asynchronously)
     * This will provide access to subscriptions in database. 
     * @param xWSO2Tenant This is used to specify the tenant domain, where the resource need to be   retrieved from.  (required)
     * @param apiId **Search condition**.   Api ID  of the subscription  (optional)
     * @param appId **Search condition**.   Application ID  of the subscription  (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 subscriptionsGetAsync(String xWSO2Tenant, Integer apiId, Integer appId, final ApiCallback<SubscriptionListDTO> 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 = subscriptionsGetValidateBeforeCall(xWSO2Tenant, apiId, appId, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<SubscriptionListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
