/** CHARAKTERBOGEN-2: map character trait KEYS (stored) <-> German LABELS (de.character.traitCategories). */
import { de } from '../strings/de'

export interface TraitEntry {
  key: string
  label: string
  warn?: true
}

export interface TraitCategory {
  category: string
  traits: readonly TraitEntry[]
}

export const TRAIT_CATEGORIES: ReadonlyArray<TraitCategory> =
  de.character.traitCategories as unknown as ReadonlyArray<TraitCategory>

export const ALL_TRAITS: readonly TraitEntry[] = TRAIT_CATEGORIES.flatMap((c) => c.traits)

const LABEL_BY_KEY = new Map<string, string>(ALL_TRAITS.map((t) => [t.key, t.label]))

export function traitLabel(key: string): string {
  return LABEL_BY_KEY.get(key) ?? key
}

/** Selected keys -> German labels (for display + the AI sale-text prompt). */
export function traitLabels(keys: readonly string[] | null | undefined): string[] {
  return (keys ?? []).map(traitLabel)
}

export function isWarnTrait(key: string): boolean {
  return ALL_TRAITS.some((t) => t.key === key && t.warn === true)
}
