// Vaar Devata module barrel. Re-exports the module's types + data and defines
// the lookup helpers (the dataset is small and date-indexed, so the helpers
// live here rather than in the top-level barrel).
import type { Deity } from '../types.js'
import type { GrahaKey, VaarDevata } from './types.js'
import { VAAR_DEVATA } from './vaar-devata.js'

export type * from './types.js'
export { VAAR_DEVATA, VAAR_SOURCES } from './vaar-devata.js'

/** The day's Vaar Devata for a given date (`Date.getDay()`-indexed). */
export function getVaarDevataForDate(d: Date): VaarDevata {
  return VAAR_DEVATA[d.getDay()]
}

/** Look up by day slug ('sunday' … 'saturday'); `undefined` for an unknown key. */
export function getVaarDevataByKey(key: string | undefined): VaarDevata | undefined {
  return VAAR_DEVATA.find((v) => v.dayKey === key)
}

/** Look up by ruling graha — e.g. for a daśā-lord weekday remedy. */
export function getVaarDevataByGraha(graha: GrahaKey): VaarDevata | undefined {
  return VAAR_DEVATA.find((v) => v.grahaKey === graha)
}

/** The day's deities that have a roster slug, de-duplicated. */
export function vaarRosterIds(v: VaarDevata): Deity[] {
  const ids: Deity[] = []
  for (const d of v.deities) {
    if (d.rosterId && !ids.includes(d.rosterId)) ids.push(d.rosterId)
  }
  return ids
}

/** The day's deity names joined for a one-line label ("Vishnu · Brihaspati · Sai Baba"). */
export function vaarDeityNames(v: VaarDevata, lang: 'en' | 'hi'): string {
  return v.deities.map((d) => d.name[lang]).join(' · ')
}
