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 {
  GetStockSimilarCarSearchParameters,
  GetStockSimilarCarSearchResponse
} 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 GetStockSimilarCarSearchService extends ApiMethodBase<
  GetStockSimilarCarSearchResponse,
  null,
  GetStockSimilarCarSearchParameters
> {
  protected get method(): 'GET' {
    return 'GET';
  }

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

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

  /**
   * 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: {
        type: 'object',
        properties: {
          similarCarSearch: {
            $ref: 'stock-cars.json#/components/schemas/SimilarCarSearch'
          },
          dictionaryValueMeta: {
            type: 'object',
            properties: {
              similarCarSearch: {
                type: 'object',
                additionalProperties: {
                  type: 'array',
                  items: {
                    $ref:
                      'stock-cars.json#/components/schemas/DictionaryValueMeta'
                  }
                }
              }
            }
          }
        },
        example: {
          similarCarSearch: {
            id: null,
            brand: 7,
            model: 727,
            generation: [5014],
            creationYear: {
              from: 2010,
              to: 2011,
              isFromInclusive: true,
              isToInclusive: true
            },
            vehicleType: [1],
            enginePower: {
              from: 120,
              to: 180,
              isFromInclusive: true,
              isToInclusive: true
            },
            engineVolume: {
              from: 1.9,
              to: 2.1,
              isFromInclusive: true,
              isToInclusive: true
            },
            engineType: [1],
            wheelType: [1],
            bodyDoors: [{ body: 4, doors: 5 }, { body: 4, doors: 3 }],
            driveType: [1, 2],
            gearType: [2],
            ownerType: [1, 2],
            status: 1,
            source: [487, 488],
            region: {
              type: 'regions',
              regions: [
                {
                  id: 1960671,
                  type: {
                    id: 103,
                    type: 'city',
                    shortName: 'г',
                    fullName: 'Город'
                  },
                  name: 'Москва',
                  coordinates: [55.75396, 37.620393],
                  distance: null,
                  count: 140701
                }
              ],
              radius: { coordinates: [55.751244, 37.618423], radius: 100 }
            },
            color: null,
            isExtendedByTwinsModels: false,
            isExtendedByMixedModels: false,
            canExtendingByTwinsModels: null,
            canExtendingByMixedModels: null,
            manualExcludedIds: [
              '2f614e016c16cced35b59f365c42fbae',
              '3fda7e6892787b274d9967955b07fc7f'
            ],
            manualIncludedIds: [],
            autoExcludedIds: [],
            climateControl: null,
            ac: null,
            parktronic: null,
            cruiseControl: null,
            startStopEngine: null,
            powerWindows: null,
            navigationSystem: null,
            backCamera: null,
            powerSteering: null,
            abs: null,
            esp: null,
            tcs: null,
            eds: null,
            airbag: null,
            airbagFront: null,
            airbagSide: null,
            airbagWindow: null,
            airbagKnees: null,
            alarm: null,
            armored: null,
            diskSize: null,
            diskType: null,
            winterTires: null,
            headlightType: null,
            fogLights: null,
            airSuspension: null,
            aerography: null,
            upholstery: null,
            heatedSeats: null,
            thirdRowSeats: null,
            sunroof: null,
            panoramicRoof: null,
            objectVersion: 0
          },
          dictionaryValueMeta: {
            similarCarSearch: {
              brand: [{ value: 7, title: 'Kia' }],
              model: [{ value: 727, title: 'Sportage' }],
              generation: [{ value: 5014, title: '3 поколение' }],
              engineType: [{ value: 1, title: 'Бензиновый' }],
              wheelType: [{ value: 1, title: 'Левый' }],
              bodyDoors: [
                { title: 'Внедорожник 5 дв.', value: { body: 4, doors: 5 } },
                { title: 'Внедорожник 3 дв.', value: { body: 4, doors: 3 } }
              ],
              vehicleType: [{ value: 1, title: 'Легковой' }],
              driveType: [
                { value: 1, title: 'Передний' },
                { value: 2, title: 'Задний' }
              ],
              gearType: [{ value: 2, title: 'Механика' }],
              ownerType: [
                { value: 1, title: 'Физическое лицо' },
                { value: 2, title: 'Юридическое лицо' }
              ]
            }
          }
        },
        description: 'Объект `SimilarCarSearch`'
      },
      request: null,
      params: {
        type: 'object',
        required: ['id'],
        properties: {
          id: { type: 'integer' },
          resolveDictionaries: { type: 'boolean' }
        },
        description:
          'Model of parameters for API /stock-cars/{id}/similar-car-search'
      }
    } as any;
  }

  /**
   * Mock data when servers is disabled (in DEV-mode).
   * @returns {any}
   */
  protected get mockData(): any {
    return {
      similarCarSearch: {
        id: null,
        brand: 7,
        model: 727,
        generation: [5014],
        creationYear: {
          from: 2010,
          to: 2011,
          isFromInclusive: true,
          isToInclusive: true
        },
        vehicleType: [1],
        enginePower: {
          from: 120,
          to: 180,
          isFromInclusive: true,
          isToInclusive: true
        },
        engineVolume: {
          from: 1.9,
          to: 2.1,
          isFromInclusive: true,
          isToInclusive: true
        },
        engineType: [1],
        wheelType: [1],
        bodyDoors: [{ body: 4, doors: 5 }, { body: 4, doors: 3 }],
        driveType: [1, 2],
        gearType: [2],
        ownerType: [1, 2],
        status: 1,
        source: [487, 488],
        region: {
          type: 'regions',
          regions: [
            {
              id: 1960671,
              type: {
                id: 103,
                type: 'city',
                shortName: 'г',
                fullName: 'Город'
              },
              name: 'Москва',
              coordinates: [55.75396, 37.620393],
              distance: null,
              count: 140701
            }
          ],
          radius: { coordinates: [55.751244, 37.618423], radius: 100 }
        },
        color: null,
        isExtendedByTwinsModels: false,
        isExtendedByMixedModels: false,
        canExtendingByTwinsModels: null,
        canExtendingByMixedModels: null,
        manualExcludedIds: [
          '2f614e016c16cced35b59f365c42fbae',
          '3fda7e6892787b274d9967955b07fc7f'
        ],
        manualIncludedIds: [],
        autoExcludedIds: [],
        climateControl: null,
        ac: null,
        parktronic: null,
        cruiseControl: null,
        startStopEngine: null,
        powerWindows: null,
        navigationSystem: null,
        backCamera: null,
        powerSteering: null,
        abs: null,
        esp: null,
        tcs: null,
        eds: null,
        airbag: null,
        airbagFront: null,
        airbagSide: null,
        airbagWindow: null,
        airbagKnees: null,
        alarm: null,
        armored: null,
        diskSize: null,
        diskType: null,
        winterTires: null,
        headlightType: null,
        fogLights: null,
        airSuspension: null,
        aerography: null,
        upholstery: null,
        heatedSeats: null,
        thirdRowSeats: null,
        sunroof: null,
        panoramicRoof: null,
        objectVersion: 0
      },
      dictionaryValueMeta: {
        similarCarSearch: {
          brand: [{ value: 7, title: 'Kia' }],
          model: [{ value: 727, title: 'Sportage' }],
          generation: [{ value: 5014, title: '3 поколение' }],
          engineType: [{ value: 1, title: 'Бензиновый' }],
          wheelType: [{ value: 1, title: 'Левый' }],
          bodyDoors: [
            { title: 'Внедорожник 5 дв.', value: { body: 4, doors: 5 } },
            { title: 'Внедорожник 3 дв.', value: { body: 4, doors: 3 } }
          ],
          vehicleType: [{ value: 1, title: 'Легковой' }],
          driveType: [
            { value: 1, title: 'Передний' },
            { value: 2, title: 'Задний' }
          ],
          gearType: [{ value: 2, title: 'Механика' }],
          ownerType: [
            { value: 1, title: 'Физическое лицо' },
            { value: 2, title: 'Юридическое лицо' }
          ]
        }
      }
    } 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);
  }
}
