import { AbstractLocationTransformer } from '../../../transformer' ; import { HereProvider } from '../here.provider' ; import type { WorldCountry } from '../../../util/world-country' ; import type { HereOneResultAddressAdditionalDataType , HereOneResultAddressType , HereOneResultType } from '../interface' ; export class HereLocationTransformer extends AbstractLocationTransformer < HereProvider , HereOneResultType > { constructor ( raw ) { super ( HereProvider , raw ) ; } async getFormattedAddress ( ) { return this . getLocationAddress ( ) . Label ; } async getLatitude ( ) { return this . raw . Location . DisplayPosition . Latitude ; } async getLongitude ( ) { return this . raw . Location . DisplayPosition . Longitude ; } async getCountry ( ) { const country = this . getAdditionalDataByKey ( 'CountryName' ) ; if ( country ) { return country ; } const cca3 = this . getLocationAddress ( ) . Country ; const worldCountry = await this . getWorldCountry ( { cca3 } ) ; return worldCountry && worldCountry . name . common ; } async getCountryCode ( ) { const countryCode = this . getAdditionalDataByKey ( 'Country2' ) ; if ( countryCode ) { return countryCode ; } const cca3 = this . getLocationAddress ( ) . Country ; const worldCountry = await this . getWorldCountry ( { cca3 } ) ; return worldCountry && worldCountry . cca2 ; } async getState ( ) { return this . getAdditionalDataByKey ( 'StateName' ) || this . getLocationAddress ( ) . State ; } async getStateCode ( ) { return this . getLocationAddress ( ) . State ; } async getCity ( ) { return this . getLocationAddress ( ) . City ; } async getPostalCode ( ) { return this . getLocationAddress ( ) . PostalCode ; } async getStreetName ( ) { return this . getLocationAddress ( ) . Street ; } async getHouseNumber ( ) { return this . getLocationAddress ( ) . HouseNumber ; } async getPlaceId ( ) { return this . raw . Location . LocationId ; } private getLocationAddress ( ) { return this . raw . Location . Address || { AdditionalData : [ ] } ; } private getAdditionalDataByKey ( key ) { const data = this . getLocationAddress ( ) . AdditionalData ?. find < HereOneResultAddressAdditionalDataType > ( ( element ) : element is HereOneResultAddressAdditionalDataType => key === element . key ) ; if ( data ) { return data . value ; } } }