import type { NominatimResult } from '../../utils/nominatim.ts'
import type { BookmarkProperties } from '../schema/v0.ts'

export function from(result: NominatimResult): BookmarkProperties {
  const a = result.address
  return {
    displayName: result.display_name,
    name: result.name,
    importance: result.importance,
    nominatimId: result.place_id,
    nominatimCategory: result.class,
    nominatimType: result.type,
    nominatimPlaceRank: result.place_rank,
    osmId: result.osm_id,
    osmType: result.osm_type,
    address: a
      ? {
        city: a.city,
        cityDistrict: a.city_district,
        country: a.country,
        countryCode: a.country_code,
        historic: a.historic,
        houseNumber: a.house_number,
        postcode: a.postcode,
        region: a.region,
        road: a.road,
        suburb: a.suburb,
        state: a.state,
        'ISO3166-2-lvl4': a['ISO3166-2-lvl4'],
        'ISO3166-2-lvl6': a['ISO3166-2-lvl6'],
      }
      : undefined,
  }
}
