/* tslint:disable */

import { HttpClient } from '@angular/common/http';
import { Inject, Injectable, Optional } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { DefaultHttpOptions, HttpOptions } from './';
import { USE_DOMAIN, USE_HTTP_OPTIONS, {{&serviceName}} } from './{{&serviceFileName}}';

{{#definitions.length}}
import * as models from '.{{#swaggerTag}}./..{{/swaggerTag}}/models';
import * as guards from '.{{#swaggerTag}}./..{{/swaggerTag}}/guards';
{{/definitions.length}}

/**
 * Created with https://github.com/flowup/api-client-generator
 */
@Injectable()
export class Guarded{{&serviceName}} extends {{&serviceName}} {

  constructor(readonly httpClient: HttpClient,
              @Optional() @Inject(USE_DOMAIN) domain?: string,
              @Optional() @Inject(USE_HTTP_OPTIONS) options?: DefaultHttpOptions) {
    super(httpClient, domain, options);
  }

{{#methods}}{{^isVoid}}
  {{&methodName}}(
  {{#parameters.length}}
    args: {
      {{#parameters}}
      {{&camelCaseName}}{{^isRequired}}?{{/isRequired}}: {{&importType}}{{#isArray}}[]{{/isArray}},{{#description}}  //{{^isRequired}} (optional){{/isRequired}} {{&.}}{{/description}}
      {{/parameters}}
    },
  {{/parameters.length}}
    requestHttpOptions?: HttpOptions
  ): Observable<{{&response}}> {
    return super.{{&methodName}}({{#parameters.length}}args, {{/parameters.length}}requestHttpOptions){{#responseGuard}}
      .pipe(tap((res: any) => {{&responseGuard}} || console.error(`TypeGuard for response '{{&responseTypeName}}' caught inconsistency.`, res))){{/responseGuard}};
  }

{{/isVoid}}{{/methods}}
}
