import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { ApiMethodBase } from 'oapi3codegen-agent-angular/api-method.base';
import { ApiSchema } from 'oapi3codegen-agent-angular/api-schema';
import {
  SERVERS_DATA,
  ServersData
} from 'oapi3codegen-agent-angular/servers.data.provider';
import {
  API_ERROR_HANDLER,
  ApiErrorHandler
} from 'oapi3codegen-agent-angular/event-manager.provider';

// Typings for this API method
import {
  GetSimilarCarsCountParameters,
  GetSimilarCarsCountResponse,
  GetSimilarCarsCountRequest
} from '../typings';

import * as domainSchema from './stock-cars.json';

/**
 * Service for angular based on ApiAgent solution.
 * Provides assured request to API method with implicit
 * validation and common errors handling scheme.
 */
@Injectable()
export class GetSimilarCarsCountService extends ApiMethodBase<
  GetSimilarCarsCountResponse,
  GetSimilarCarsCountRequest,
  GetSimilarCarsCountParameters
> {
  protected get method(): 'POST' {
    return 'POST';
  }

  /**
   * Path template, example: `/some/path/{id}`.
   * @returns {string}
   */
  protected get pathTemplate(): string {
    return '/stock-cars/similar/count';
  }

  /**
   * Parameters in a query.
   * @returns {string[]}
   */
  protected get queryParams(): string[] {
    return ['excludeCurrent'];
  }

  /**
   * API servers.
   * @returns {string[]}
   */
  protected get servers(): string[] {
    return ['http://lk.cm.local/api/site/'];
  }

  /**
   * Complete domain API schema (OAS3) with library
   * of models.
   * @returns {SubSchema}
   */
  protected get domainSchema(): any {
    return domainSchema;
  }

  /**
   * JSON Schemas using for validations at requests.
   * @returns {Schema}
   */
  protected get schema(): ApiSchema {
    return {
      response: {
        $ref: 'stock-cars.json#/components/schemas/CountInfo',
        description: 'Информация о количестве найденных автомобилей'
      },
      request: {
        type: 'object',
        required: ['stockCar'],
        properties: {
          stockCar: { $ref: 'stock-cars.json#/components/schemas/StockCar' },
          similarCarSearch: {
            $ref: 'stock-cars.json#/components/schemas/SimilarCarSearch'
          }
        }
      },
      params: {
        type: 'object',
        required: [],
        properties: { excludeCurrent: { type: 'boolean', default: false } },
        description: 'Model of parameters for API /stock-cars/similar/count'
      }
    } as any;
  }

  /**
   * Mock data when servers is disabled (in DEV-mode).
   * @returns {any}
   */
  protected get mockData(): any {
    return {} as any;
  }

  // *** Methods

  /**
   * @param {HttpClient} httpClient
   * @param {ApiErrorHandler} errorHandler
   * Обработчик ошибок HTTP-запросов и
   * @param {ServersData} serversData
   */
  constructor(
    protected httpClient: HttpClient,
    @Inject(API_ERROR_HANDLER) protected errorHandler: ApiErrorHandler,
    @Inject(SERVERS_DATA) protected serversData: ServersData
  ) {
    super(httpClient, errorHandler, serversData, domainSchema);
  }
}
