/* tslint:disable */

/**
 * This file was automatically generated by "Swaxios".
 * It should not be modified by hand.
 */

import {AxiosInstance, AxiosRequestConfig} from 'axios';
{{#if imports.list.length}}
import {
  {{#each imports.list}}
    {{{this}}},
  {{/each}}
} from '{{{imports.path}}}'
{{/if}}

export class {{{name}}} {
  private readonly apiClient: AxiosInstance;

  constructor(apiClient: AxiosInstance) {
    this.apiClient = apiClient;
  }
  {{#each methods}}

    {{#if this.descriptions}}
      /**
      {{#each this.descriptions}}
       * @param {{{this.name}}} {{{this.text}}}
      {{/each}}
       */
    {{/if}}
    {{{this.parameterMethod}}} = async (
      {{#each this.pathParameters}}
        {{{this.name}}}: {{{this.type}}},
      {{/each}}
      {{#each this.bodyParameters}}
        {{{this.name}}}{{#isnt this.required true}}?{{/isnt}}: {{{this.type}}},
      {{/each}}
      {{#if this.requiresBearerAuthorization}}
        accessTokenCallback: () => Promise<string>,
      {{/if}}
      {{#if this.queryParameters.length}}
        params?: {
          {{#each this.queryParameters}}
            {{{this.name}}}{{#isnt this.required true}}?{{/isnt}}: {{{this.type}}};
          {{/each}}
        }
      {{/if}}
    ): Promise<{{{this.returnType}}}> => {
      {{#if this.requiresBearerAuthorization}}
        const accessToken = await accessTokenCallback();
      {{/if}}
      const config: AxiosRequestConfig = {
        {{#if this.bodyParameters.length}}
          data: {
            {{#each this.bodyParameters}}
              ...{{this.name}},
            {{/each}}
          },
        {{/if}}
        {{#if this.requiresBearerAuthorization}}
          headers: {
            Authorization: `Bearer ${decodeURIComponent(accessToken)}`,
          },
        {{/if}}
        method: '{{{this.method}}}',
        {{#if this.queryParameters.length}}
          params,
        {{/if}}
        url: {{{this.formattedUrl}}},
      }
      {{#eq this.returnType "void"}}
        await this.apiClient.request
      {{else}}
        const response = await this.apiClient.request<{{{this.returnType}}}>
      {{/eq}}
      (config);
      {{#isnt this.returnType "void"}}
        return response.data;
      {{/isnt}}
    };
  {{/each}}
}
