{{>licenseInfo}}
import ApiClient from '../ApiClient';
{{#imports}}
import {{&import}} from '../{{#modelPackage}}{{&modelPackage}}/{{/modelPackage}}{{&import}}';
{{/imports}}

/**
 * {{baseName}} service.
 * @module {{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{classname}}
 */
export default class {{classname}} extends ApiClient {
    /**
    {{#description}}
     * {{description}}
    {{/description}}
     * @class
     * { string } basePath To override basePath.
     * { object } headers Additional headers for the instance.
     * { int } timeout Number in seconds before timeout.
     */
    constructor(
        basePath = null,
        headers = null,
        timeout = null
    ) {
        super(basePath, headers, timeout);
    }
{{#operations}}{{#operation}}
    /**
    {{#summary}}
     * {{summary}}
    {{/summary}}
    {{#notes}}
     * {{notes}}
    {{/notes}}
    {{#allParams}}
        {{#required}}
     * @param { {{&vendorExtensions.x-jsdoc-type}} } {{paramName}}{{#description}} {{&description}}{{/description}}
        {{/required}}
    {{/allParams}}
    {{#hasAuthMethods}}
     * @param { Object } credentials The required credentials with good properties to use different types of authentication.
    {{/hasAuthMethods}}
     * @param {{#returnType}}{ {{&returnType}} } {{/returnType}}{{^returnType}}{ Object }{{/returnType}} returnType The required type to return; can be a string for simple types or the constructor for a complex type{{^returnType}} (default to null){{/returnType}}.
    {{#allParams}}
        {{^required}}
     * @param { {{&vendorExtensions.x-jsdoc-type}} } {{paramName}} {{description}} {{#defaultValue}} (default to {{.}}){{/defaultValue}}
        {{/required}}
    {{/allParams}}
     */
    {{operationId}}(
        returnType = null,
        options,
    {{#hasAuthMethods}}
        credentials,
    {{/hasAuthMethods}}
    ) {
        {{#returnType}}
        if (returnType === null) {
            returnType = {{&returnType}};
        }
        {{/returnType}}

        let {
        {{#allParams}}
            {{&paramName}},
        {{/allParams}}
        } = options;

        {{#allParams}}{{#required}}
        // verify the required parameter '{{&paramName}}' is set
        if (typeof {{&paramName}} === 'undefined' || {{&paramName}} === null) {
            throw new window.Error('Missing the required parameter "{{&paramName}}" when calling {{&operationId}}');
        }
        {{/required}}{{/allParams}}

        {{#allParams}}{{^required}}{{#defaultValue}}
        // verify the default value of parameter '{{&paramName}}'
        if (typeof {{paramName}} === 'undefined' || {{paramName}} === null) {
            {{&paramName}} = {{#example}}{{&example}}{{/example}};  // eslint-disable-line quotes
        }
        {{/defaultValue}}{{/required}}{{/allParams}}

        {{#allParams}}{{^required}}{{^defaultValue}}
        // verify the null value of parameter '{{&paramName}}'
        if (typeof {{paramName}} === 'undefined') {
            {{&paramName}} = null;
        }
        {{/defaultValue}}{{/required}}{{/allParams}}

        {{#hasAuthMethods}}
        if (typeof credentials === 'undefined' || credentials === null) {
            throw new window.Error('Missing the required parameter "credentials" when calling {{&operationId}}');
        }
        {{/hasAuthMethods}}

        let pathParams = {
        {{#pathParams}}
            '{{&baseName}}': {{&paramName}},
        {{/pathParams}}
        };

        {{#bodyParam}}
        let bodyParam = {{&paramName}};
        {{/bodyParam}}
        {{^bodyParam}}
        let bodyParam = null;
        {{/bodyParam}}

        let queryParams = {
            {{#queryParams}}
            '{{&baseName}}': {{&paramName}},
            {{/queryParams}}
        };

        let headerParams = {
            {{#headerParams}}
            '{{&baseName}}': {{&paramName}},
            {{/headerParams}}
        };

        {{#hasAuthMethods}}
        let credentialParams = credentials;
        {{/hasAuthMethods}}
        {{^hasAuthMethods}}
        let credentialParams = null;
        {{/hasAuthMethods}}

        let authNames = [
            {{#authMethods}}
            '{{&name}}',
            {{/authMethods}}
        ];

        let contentTypes = [
            {{#consumes}}
            '{{&mediaType}}',
            {{/consumes}}
        ];

        let accepts = [
            {{#produces}}
            '{{&mediaType}}',
            {{/produces}}
        ];

        return this.callApi(
            '{{&path}}',
            '{{&httpMethod}}',
            pathParams,
            queryParams,
            headerParams,
            bodyParam,
            authNames,
            credentialParams,
            contentTypes,
            accepts,
            returnType
        );
    }
{{/operation}}{{/operations}}
}
