package {{packageName}}

{{#operations}}
import (
	"strings"
	"fmt"
	"errors"
	{{#imports}}"{{import}}"
{{/imports}}
)

type {{classname}} struct {
	Configuration Configuration
}

func New{{classname}}() *{{classname}} {
	configuration := NewConfiguration()
	return &{{classname}}{
		Configuration: *configuration,
	}
}

func New{{classname}}WithBasePath(basePath string) *{{classname}} {
	configuration := NewConfiguration()
	configuration.BasePath = basePath

	return &{{classname}}{
		Configuration: *configuration,
	}
}
{{#operation}}

/**
 * {{summary}}{{#notes}}
 * {{notes}}{{/notes}}
 *
{{#allParams}} * @param {{paramName}} {{description}}
{{/allParams}} * @return {{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
 */
func (a {{classname}}) {{nickname}}({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{^isListContainer}}*{{/isListContainer}}{{{returnType}}}, {{/returnType}}*APIResponse, error) {

	var httpMethod = "{{httpMethod}}"
	// create path and map variables
	path := a.Configuration.BasePath + "{{path}}"{{#pathParams}}
	path = strings.Replace(path, "{"+"{{baseName}}"+"}", fmt.Sprintf("%v", {{paramName}}), -1){{/pathParams}}
{{#allParams}}{{#required}}
	// verify the required parameter '{{paramName}}' is set
	if &{{paramName}} == nil {
		return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}new({{{returnType}}}), {{/returnType}}nil, errors.New("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
	}{{/required}}{{/allParams}}

	headerParams := make(map[string]string)
	queryParams := make(map[string]string)
	formParams := make(map[string]string)
	var postBody interface{}
	var fileName string
	var fileBytes []byte
{{#authMethods}}
	// authentication ({{name}}) required
{{#isApiKey}}{{#isKeyInHeader}}
	// set key with prefix in header
	headerParams["{{keyParamName}}"] = a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}")
{{/isKeyInHeader}}{{#isKeyInQuery}}
	// set key with prefix in querystring{{#hasKeyParamName}}
	queryParams["{{keyParamName}}"] =  a.Configuration.GetAPIKeyWithPrefix("{{keyParamName}}")
{{/hasKeyParamName}}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
	// http basic authentication required
	if a.Configuration.Username != "" || a.Configuration.Password != ""{
		headerParams["Authorization"] =  "Basic " + a.Configuration.GetBasicAuthEncodedString()
	}{{/isBasic}}{{#isOAuth}}
	// oauth required
	if a.Configuration.AccessToken != ""{
		headerParams["Authorization"] =  "Bearer " + a.Configuration.AccessToken
	}{{/isOAuth}}{{/authMethods}}
	// add default headers if any
	for key := range a.Configuration.DefaultHeader {
		headerParams[key] = a.Configuration.DefaultHeader[key]
	}{{#hasQueryParams}}{{#queryParams}}

	queryParams["{{paramName}}"] = a.Configuration.APIClient.ParameterToString({{paramName}})
	{{/queryParams}}{{/hasQueryParams}}

	// to determine the Content-Type header
	localVarHttpContentTypes := []string{ {{#consumes}}"{{mediaType}}", {{/consumes}} }

	// set Content-Type header
	localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
	if localVarHttpContentType != "" {
		headerParams["Content-Type"] = localVarHttpContentType
	}
	// to determine the Accept header
	localVarHttpHeaderAccepts := []string{
		{{#produces}}"{{mediaType}}",
{{/produces}}	}

	// set Accept header
	localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
	if localVarHttpHeaderAccept != "" {
		headerParams["Accept"] = localVarHttpHeaderAccept
	}{{#hasHeaderParams}}

{{#headerParams}}	// header params "{{baseName}}"
	headerParams["{{baseName}}"] = {{paramName}}
{{/headerParams}}{{/hasHeaderParams}}{{#hasFormParams}}
{{#formParams}}{{#isFile}}
	fbs, _ := ioutil.ReadAll(file)
	fileBytes = fbs
	fileName = file.Name(){{/isFile}}
{{^isFile}}	formParams["{{paramName}}"] = {{paramName}}{{/isFile}}{{/formParams}}{{/hasFormParams}}{{#hasBodyParam}}
{{#bodyParams}}	// body params
	postBody = &{{paramName}}
{{/bodyParams}}{{/hasBodyParam}}
{{#returnType}}	var successPayload = new({{returnType}}){{/returnType}}
	httpResponse, err := a.Configuration.APIClient.CallAPI(path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
	if err != nil {
		return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err
	}
{{#returnType}}
	err = json.Unmarshal(httpResponse.Body(), &successPayload){{/returnType}}
	return {{#returnType}}{{#isListContainer}}*{{/isListContainer}}successPayload, {{/returnType}}NewAPIResponse(httpResponse.RawResponse), err
}
{{/operation}}{{/operations}}
