import { Injectable } from '@nestjs/common'; import { ICreateGeorouter } from '../../domain/interfaces/georouter-creator.interface'; import { IGeorouter } from '../../domain/interfaces/georouter.interface'; import { GraphhopperGeorouter } from './graphhopper-georouter'; import { HttpService } from '@nestjs/axios'; import { Geodesic } from './geodesic'; import { GeographyException } from '../../exceptions/geography.exception'; import { ExceptionCode } from '../../../utils/exception-code.enum'; @Injectable() export class GeorouterCreator implements ICreateGeorouter { constructor( private readonly httpService: HttpService, private readonly geodesic: Geodesic, ) {} create = (type: string, url: string): IGeorouter => { switch (type) { case 'graphhopper': return new GraphhopperGeorouter(url, this.httpService, this.geodesic); default: throw new GeographyException( ExceptionCode.INVALID_ARGUMENT, 'Unknown geocoder', ); } }; }