/**
 * ZUCHT-SUFFIX: a gerbil's display name with the own-Zucht "suffix" (like a last
 * name) appended — "Danako" + "von den kleinen Chaoten" → "Danako von den kleinen
 * Chaoten". Per the chosen rule, only OWN-bred animals get the suffix; animals from
 * other breeders keep their plain name.
 */
import type { Gerbil } from '../api/types'

type NameParts = Pick<Gerbil, 'name' | 'originContactId' | 'originBreeder'>

/** Own-bred = no external origin recorded (no origin contact, no freetext breeder). */
export function isOwnBred(g: NameParts): boolean {
  if (g.originContactId) return false
  const b = g.originBreeder?.trim().toLowerCase()
  if (!b) return true
  return b.includes('chaoten')
}

/**
 * Name + own-Zucht suffix for own-bred animals; plain name otherwise.
 * Returns '' for a nameless animal (callers fall back to the "(ohne Namen)" label).
 */
export function gerbilDisplayName(g: NameParts, ownSuffix: string): string {
  if (!g.name) return ''
  const suffix = ownSuffix.trim()
  return suffix && isOwnBred(g) ? `${g.name} ${suffix}` : g.name
}
