import { normalizeAumlauts } from "./normalizeAumlauts"

import type { Location } from "@/types/trpc/routers/hotel/locations"

export function getSearchTokens(location: Location) {
  const tokens = [
    ...(location.keyWords?.map((x) => x.toLocaleLowerCase()) ?? []),
    location.name,
    location.type === "hotels"
      ? location.relationships.city.name
      : location.country,
  ]
    .filter(hasValue)
    .map((x) => x.toLocaleLowerCase())

  const normalizedTokens = normalizeAumlauts(tokens)
  return normalizedTokens
}

function hasValue(value: string | null | undefined): value is string {
  return !!value && value.length > 0
}
