import type { AxiosInstance } from 'axios' ; import { GeocodeCommand } from '../../../command' ; import type { GeocodeQuery } from '../../../model' ; import type { GoogleMapsGeocodeQueryInterface } from '../interface' ; import { GoogleMapsLocationCommandMixin } from './mixin' ; link export class GoogleMapsGeocodeCommand extends GoogleMapsLocationCommandMixin ( GeocodeCommand ) < GoogleMapsGeocodeQueryInterface > { constructor ( httpClient , private readonly apiKey ) { super ( httpClient , apiKey ) ; } static getUrl ( ) { return 'https://maps.googleapis.com/maps/api/geocode/json' ; } protected async buildQuery ( query ) { const components = new Map < string , string > ( ) ; if ( query . postalCode ) { components . set ( 'postal_code' , query . postalCode ) ; } const country = query . countryCode || query . country ; if ( country ) { components . set ( 'country' , country ) ; } const state = query . stateCode || query . state ; if ( state ) { components . set ( 'administrative_area' , state ) ; } const providerQuery = { key : this . apiKey , address : query . address , components : [ ... components ] . map < string > ( ( [ key , value ] ) => `${ key }:${ value }` ) . join ( '|' ) , language : query . language , limit : query . limit , sensor : false , } ; if ( query . countryCode ) { providerQuery . region = `.${ query . countryCode . toLowerCase ( ) }` ; } return providerQuery ; } }