/*
 * WSO2 API Manager - Publisher API
 * This specifies a **RESTful API** for WSO2 **API Manager** - Publisher.  Please see [full swagger definition](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.0.4/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher/src/main/resources/publisher-api.yaml) of the API which is written using [swagger 2.0](http://swagger.io/) specification. 
 *
 * OpenAPI spec version: v1.1
 * Contact: architecture@wso2.com
 *
 * 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.publisher.api.v1;

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

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import org.wso2.am.integration.clients.publisher.api.v1.dto.ErrorDTO;
import java.io.File;
import org.wso2.am.integration.clients.publisher.api.v1.dto.MediationDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.MediationListDTO;

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

public class ApiMediationPoliciesApi {
    private ApiClient apiClient;

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

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

    /**
     * Build call for apisApiIdMediationPoliciesGet
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param limit Maximum size of resource array to return.  (optional, default to 25)
     * @param offset Starting point within the complete list of items qualified.  (optional, default to 0)
     * @param query -Not supported yet- (optional)
     * @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.  (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 apisApiIdMediationPoliciesGetCall(String apiId, Integer limit, Integer offset, String query, String ifNoneMatch, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/apis/{apiId}/mediation-policies"
            .replaceAll("\\{" + "apiId" + "\\}", apiClient.escapeString(apiId.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));
        if (query != null)
        localVarQueryParams.addAll(apiClient.parameterToPair("query", query));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        if (ifNoneMatch != null)
        localVarHeaderParams.put("If-None-Match", apiClient.parameterToString(ifNoneMatch));

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

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

        com.squareup.okhttp.Call call = apisApiIdMediationPoliciesGetCall(apiId, limit, offset, query, ifNoneMatch, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Get all mediation policies of an API 
     * This operation provides you a list of available mediation policies of an API. 
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param limit Maximum size of resource array to return.  (optional, default to 25)
     * @param offset Starting point within the complete list of items qualified.  (optional, default to 0)
     * @param query -Not supported yet- (optional)
     * @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.  (optional)
     * @return MediationListDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public MediationListDTO apisApiIdMediationPoliciesGet(String apiId, Integer limit, Integer offset, String query, String ifNoneMatch) throws ApiException {
        ApiResponse<MediationListDTO> resp = apisApiIdMediationPoliciesGetWithHttpInfo(apiId, limit, offset, query, ifNoneMatch);
        return resp.getData();
    }

    /**
     * Get all mediation policies of an API 
     * This operation provides you a list of available mediation policies of an API. 
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param limit Maximum size of resource array to return.  (optional, default to 25)
     * @param offset Starting point within the complete list of items qualified.  (optional, default to 0)
     * @param query -Not supported yet- (optional)
     * @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.  (optional)
     * @return ApiResponse&lt;MediationListDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<MediationListDTO> apisApiIdMediationPoliciesGetWithHttpInfo(String apiId, Integer limit, Integer offset, String query, String ifNoneMatch) throws ApiException {
        com.squareup.okhttp.Call call = apisApiIdMediationPoliciesGetValidateBeforeCall(apiId, limit, offset, query, ifNoneMatch, null, null);
        Type localVarReturnType = new TypeToken<MediationListDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Get all mediation policies of an API  (asynchronously)
     * This operation provides you a list of available mediation policies of an API. 
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param limit Maximum size of resource array to return.  (optional, default to 25)
     * @param offset Starting point within the complete list of items qualified.  (optional, default to 0)
     * @param query -Not supported yet- (optional)
     * @param ifNoneMatch Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.  (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 apisApiIdMediationPoliciesGetAsync(String apiId, Integer limit, Integer offset, String query, String ifNoneMatch, final ApiCallback<MediationListDTO> 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 = apisApiIdMediationPoliciesGetValidateBeforeCall(apiId, limit, offset, query, ifNoneMatch, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<MediationListDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for apisApiIdMediationPoliciesPost
     * @param type Type of the mediation sequence (required)
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param mediationPolicyFile Mediation Policy to upload (optional)
     * @param inlineContent Inline content of the Mediation Policy (optional)
     * @param ifMatch Validator for conditional requests; based on ETag.  (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 apisApiIdMediationPoliciesPostCall(String type, String apiId, File mediationPolicyFile, String inlineContent, String ifMatch, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/apis/{apiId}/mediation-policies"
            .replaceAll("\\{" + "apiId" + "\\}", apiClient.escapeString(apiId.toString()));

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

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

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();
        if (mediationPolicyFile != null)
        localVarFormParams.put("mediationPolicyFile", mediationPolicyFile);
        if (inlineContent != null)
        localVarFormParams.put("inlineContent", inlineContent);
        if (type != null)
        localVarFormParams.put("type", type);

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

        final String[] localVarContentTypes = {
            "multipart/form-data"
        };
        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[] { "OAuth2Security" };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }

    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call apisApiIdMediationPoliciesPostValidateBeforeCall(String type, String apiId, File mediationPolicyFile, String inlineContent, String ifMatch, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'type' is set
        if (type == null) {
            throw new ApiException("Missing the required parameter 'type' when calling apisApiIdMediationPoliciesPost(Async)");
        }
        
        // verify the required parameter 'apiId' is set
        if (apiId == null) {
            throw new ApiException("Missing the required parameter 'apiId' when calling apisApiIdMediationPoliciesPost(Async)");
        }
        

        com.squareup.okhttp.Call call = apisApiIdMediationPoliciesPostCall(type, apiId, mediationPolicyFile, inlineContent, ifMatch, progressListener, progressRequestListener);
        return call;

    }

    /**
     * Add an API specific mediation policy
     * This operation can be used to add an API specifc mediation policy. 
     * @param type Type of the mediation sequence (required)
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param mediationPolicyFile Mediation Policy to upload (optional)
     * @param inlineContent Inline content of the Mediation Policy (optional)
     * @param ifMatch Validator for conditional requests; based on ETag.  (optional)
     * @return MediationDTO
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public MediationDTO apisApiIdMediationPoliciesPost(String type, String apiId, File mediationPolicyFile, String inlineContent, String ifMatch) throws ApiException {
        ApiResponse<MediationDTO> resp = apisApiIdMediationPoliciesPostWithHttpInfo(type, apiId, mediationPolicyFile, inlineContent, ifMatch);
        return resp.getData();
    }

    /**
     * Add an API specific mediation policy
     * This operation can be used to add an API specifc mediation policy. 
     * @param type Type of the mediation sequence (required)
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param mediationPolicyFile Mediation Policy to upload (optional)
     * @param inlineContent Inline content of the Mediation Policy (optional)
     * @param ifMatch Validator for conditional requests; based on ETag.  (optional)
     * @return ApiResponse&lt;MediationDTO&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<MediationDTO> apisApiIdMediationPoliciesPostWithHttpInfo(String type, String apiId, File mediationPolicyFile, String inlineContent, String ifMatch) throws ApiException {
        com.squareup.okhttp.Call call = apisApiIdMediationPoliciesPostValidateBeforeCall(type, apiId, mediationPolicyFile, inlineContent, ifMatch, null, null);
        Type localVarReturnType = new TypeToken<MediationDTO>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Add an API specific mediation policy (asynchronously)
     * This operation can be used to add an API specifc mediation policy. 
     * @param type Type of the mediation sequence (required)
     * @param apiId **API ID** consisting of the **UUID** of the API.  (required)
     * @param mediationPolicyFile Mediation Policy to upload (optional)
     * @param inlineContent Inline content of the Mediation Policy (optional)
     * @param ifMatch Validator for conditional requests; based on ETag.  (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 apisApiIdMediationPoliciesPostAsync(String type, String apiId, File mediationPolicyFile, String inlineContent, String ifMatch, final ApiCallback<MediationDTO> 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 = apisApiIdMediationPoliciesPostValidateBeforeCall(type, apiId, mediationPolicyFile, inlineContent, ifMatch, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<MediationDTO>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
