{{>licenseInfo}}
import {{braces "left"}}ApiClient{{braces "right"}} from "../ApiClient";
var Collection = require('../utils/collection');

{{#emitJSDoc}}/**
* {{baseName}} service.
* @module {{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{classname}}
* @version {{projectVersion}}
*/{{/emitJSDoc}}
export class {{classname}} {

    {{#emitJSDoc}}/**
    * Constructs a new {{&classname}}. {{#description}}
    * {{description}}{{/description}}
    * @alias module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{apiPackage}}/{{/apiPackage}}{{classname}}
    * @class
    * @param {{braces "left"}}module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}ApiClient{{braces "right"}} [apiClient] Optional API client implementation to use,
    * default to {{braces "left"}}@link module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}ApiClient#instanc
    e{{braces "right"}} if unspecified.
    */{{/emitJSDoc}}
    constructor(apiClient) {
        this.apiClient = apiClient || ApiClient.instance;
    }

{{#operations}}{{#operation}}{{#emitJSDoc}}{{^usePromises}}
    /**
     * Callback function to receive the result of the {{operationId}} operation.
     * @callback module{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{apiPackage}}/{{/apiPackage}}{{classname}}~{{operationId}}Callback
     * @param {{braces "left"}}String{{braces "right"}} error Error message, if any.
     * @param {{#vendorExtensions.x-jsdoc-type}}{{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "left"}} data The data returned by the service call.{{/vendorExtensions.x-jsdoc-type}}{{^vendorExtensions.x-jsdoc-type}}data This operation does not return a value.{{/vendorExtensions.x-jsdoc-type}}
     * @param {{braces "left"}}String{{braces "right"}} response The complete HTTP response.
     */{{/usePromises}}

    /**{{#summary}}
     * {{summary}}{{/summary}}{{#notes}}
     * {{notes}}{{/notes}}{{#allParams}}{{#required}}
     * @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} {{paramName}} {{description}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
     * @param {{braces "left"}}Object{{braces "right"}} opts Optional parameters{{#allParams}}{{^required}}
     * @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} opts.{{paramName}} {{description}}{{#defaultValue}} (default to <.>){{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}{{^usePromises}}
     * @param {{braces "left"}}module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{classname}}~{{operationId}}Callback{{braces "right"}} callback The callback function, accepting three arguments: error, data, response{{#returnType}}
     * data is of type: {{braces "left"}}@link <&vendorExtensions.x-jsdoc-type>{{braces "right"}}{{/returnType}}{{/usePromises}}{{#usePromises}}
     * @return {{braces "left"}}Promise{{braces "right"}} a {{braces "left"}}@link https://www.promisejs.org/|Promise{{braces "right"}}{{#returnType}}, with an object containing data and HTTP response{{/returnType}}{{^returnType}}, with an object containing HTTP response{{/returnType}}{{/usePromises}}
     */
{{/emitJSDoc}}    {{operationId}}{{#usePromises}}WithHttpInfo{{/usePromises}}({{vendorExtensions.x-codegen-arg-list}}{{^usePromises}}{{#hasParams}}, {{/hasParams}}callback{{/usePromises}}) {
        {{#hasOptionalParams}}opts = opts || {};{{/hasOptionalParams}}
        let postBody = {{#bodyParam}}{{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
        // verify the required parameter '{{paramName}}' is set
        if ({{paramName}} === undefined || {{paramName}} === null) {
            throw new Error("Missing the required parameter '{{paramName}}' when calling {{operationId}}");
        }
{{/required}}{{/allParams}}

        let pathParams = {
            {{#pathParams}}'{{baseName}}': {{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{#hasMore}},{{/hasMore}}{{/pathParams}}
        };
        let queryParams = {};
        {{#hasOptionalParams}}
        opts = opts || {};
        queryParams = opts;
        {{/hasOptionalParams}}
        {{#queryParams}}{{#required}}
        queryParams['{{baseName}}'] = {{paramName}};
        {{/required}}{{/queryParams}}

        {{#vendorExtensions.x-codegen-isSearchTasksForWorkspace}}
        // Checks if the user provided custom field query parameters and adds it to the request
        for (const [key, value] of Object.entries(opts)) {
            var matchDotCase = /custom_fields\.(.*?)\..*/;
            var matchSnakeCase = /custom_fields_(.*?)_.*/;
            // If the provided custom fields query param key is in the following format: custom_fields.<CUSTOM_FIELD_GID>.<QUERY> (EX: custom_fields.123.is_set)
            if (matchDotCase.test(key)) {
                queryParams[key] = value;
            // If the provided custom fields query param key is in the following format: custom_fields_<CUSTOM_FIELD_GID>_<QUERY> (EX: custom_fields_123_is_set)
            } else if (matchSnakeCase.test(key)) {
                var custom_field_gid = matchSnakeCase.exec(key)[1];
                var custom_field_query_param_key = key.replace(`custom_fields_${custom_field_gid}_`, `custom_fields.${custom_field_gid}.`);
                queryParams[custom_field_query_param_key] = value;
            }
        }
        {{/vendorExtensions.x-codegen-isSearchTasksForWorkspace}}
        let headerParams = {
            {{#headerParams}}'{{baseName}}': {{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{#hasMore}},{{/hasMore}}{{/headerParams}}
        };
        let formParams = {
            {{#formParams}}'{{baseName}}': {{#collectionFormat}}this.apiClient.buildCollectionParam({{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}, '{{collectionFormat}}'){{/collectionFormat}}{{^collectionFormat}}{{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{/collectionFormat}}{{#hasMore}},{{/hasMore}}{{/formParams}}
        };

        let authNames = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
        let contentTypes = [{{#consumes}}'{{& mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}];
        let accepts = [{{#produces}}'{{& mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}];
        let returnType = 'Blob';
        {{#vendorExtensions.x-codegen-isArrayResponse}}
        // Check if RETURN_COLLECTION is set and return a collection object if it is
        if (this.apiClient.RETURN_COLLECTION) {
            return Collection.fromApiClient(
                this.apiClient.callApi(
                    '{{&path}}', '{{httpMethod}}',
                    pathParams, queryParams, headerParams, formParams, postBody,
                    authNames, contentTypes, accepts, returnType{{^usePromises}}, callback{{/usePromises}}
                ),
                this.apiClient,
                {
                    'path': '{{&path}}',
                    'httpMethod': '{{httpMethod}}',
                    'pathParams': pathParams,
                    'queryParams': queryParams,
                    'headerParams': headerParams,
                    'formParams': formParams,
                    'bodyParam': postBody,
                    'authNames': authNames,
                    'contentTypes': contentTypes,
                    'accepts': accepts,
                    'returnType': returnType
                }
            )
        }
        {{/vendorExtensions.x-codegen-isArrayResponse}}

        return this.apiClient.callApi(
            '{{&path}}', '{{httpMethod}}',
            pathParams, queryParams, headerParams, formParams, postBody,
            authNames, contentTypes, accepts, returnType{{^usePromises}}, callback{{/usePromises}}
        );
    }
{{#usePromises}}
    {{#emitJSDoc}}

    /**{{#summary}}
     * {{summary}}{{/summary}}{{#notes}}
     * {{notes}}{{/notes}}{{#allParams}}{{#required}}
     * @param {{braces "left"}}<&vendorExtensions.x-jsdoc-type>{{braces "right"}} {{paramName}} {{description}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
     * @param {{braces "left"}}Object{{braces "right"}} opts Optional parameters{{#allParams}}{{^required}}
     * @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} opts.{{paramName}} {{description}}{{#defaultValue}} (default to <.>){{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}{{^usePromises}}
     * @param {{braces "left"}}module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{classname}}~{{operationId}}Callback{{braces "right"}} callback The callback function, accepting three arguments: error, data, response{{#returnType}}
     * data is of type: {{braces "left"}}@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}}{{/returnType}}{{/usePromises}}{{#usePromises}}
     * @return {{braces "left"}}Promise{{braces "right"}} a {{braces "left"}}@link https://www.promisejs.org/|Promise{{braces "right"}}{{#returnType}}, with data of type {{braces "left"}}@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}}{{/returnType}}{{/usePromises}}
     */
{{/emitJSDoc}}    {{operationId}}({{vendorExtensions.x-codegen-arg-list}}) {
        {{#vendorExtensions.x-codegen-isArrayResponse}}
        // Check if RETURN_COLLECTION is set and return a collection object if it is
        if (this.apiClient.RETURN_COLLECTION) {
            return this.{{operationId}}WithHttpInfo({{vendorExtensions.x-codegen-arg-list}})
        }
        {{/vendorExtensions.x-codegen-isArrayResponse}}

        return this.{{operationId}}WithHttpInfo({{vendorExtensions.x-codegen-arg-list}})
            .then(function(response_and_data) {
                return response_and_data.data;
            });
    }
{{/usePromises}}
{{/operation}}{{/operations}}

}
