package {{package}};

import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.TypeRef;

import {{modelPackage}}.*;

import java.util.*;

{{#imports}}import {{import}};
{{/imports}}

import java.io.File;
import java.util.Map;
import java.util.HashMap;

{{>generatedAnnotation}}
{{#operations}}
public class {{classname}} {
  private ApiClient {{localVariablePrefix}}apiClient;

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

  public {{classname}}(ApiClient apiClient) {
    this.{{localVariablePrefix}}apiClient = apiClient;
  }

  public ApiClient getApiClient() {
    return {{localVariablePrefix}}apiClient;
  }

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

  {{#operation}}
  /**
   * {{summary}}
   * {{notes}}
{{#allParams}}   * @param {{paramName}} {{description}}
{{/allParams}}   * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
   */
  public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
    Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
    {{#allParams}}{{#required}}
    // verify the required parameter '{{paramName}}' is set
    if ({{paramName}} == null) {
      throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
    }
    {{/required}}{{/allParams}}
    // create path and map variables
    String {{localVariablePrefix}}path = "{{{path}}}".replaceAll("\\{format\\}","json"){{#pathParams}}
      .replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};

    // query params
    List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();
    Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();
    Map<String, Object> {{localVariablePrefix}}formParams = new HashMap<String, Object>();

    {{#queryParams}}
    {{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
    {{/queryParams}}

    {{#headerParams}}if ({{paramName}} != null)
    {{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));
    {{/headerParams}}

    {{#formParams}}if ({{paramName}} != null)
      {{localVariablePrefix}}formParams.put("{{baseName}}", {{paramName}});
    {{/formParams}}

    final String[] {{localVariablePrefix}}accepts = {
      {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
    };
    final String {{localVariablePrefix}}accept = {{localVariablePrefix}}apiClient.selectHeaderAccept({{localVariablePrefix}}accepts);

    final String[] {{localVariablePrefix}}contentTypes = {
      {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
    };
    final String {{localVariablePrefix}}contentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}contentTypes);

    String[] {{localVariablePrefix}}authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };

    {{#returnType}}
    TypeRef {{localVariablePrefix}}returnType = new TypeRef<{{{returnType}}}>() {};
    return {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, {{localVariablePrefix}}returnType);
    {{/returnType}}{{^returnType}}
    {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, null);
    {{/returnType}}
  }
  {{/operation}}
}
{{/operations}}
