/**
 * API DTO types — mirror the backend (DATA-1/DATA-2) contract.
 *
 * Code is English/camelCase (matching the DTOs); German is UI-only (de.ts).
 * Enums are string unions matching the C# member names verbatim (assumes
 * JsonStringEnumConverter on the backend — confirmed with DATA-2).
 */

/** Gerbil.Gender — C# enum { unknown, male, female }. */
export type Gender = 'unknown' | 'male' | 'female'
export const GENDERS: Gender[] = ['unknown', 'male', 'female']

/** Gerbil.Status — C# enum { Active, Deceased, GivenAway, ForSale }. */
export type GerbilStatus = 'Active' | 'Deceased' | 'GivenAway' | 'ForSale'
export const GERBIL_STATUSES: GerbilStatus[] = ['Active', 'ForSale', 'Deceased', 'GivenAway']

/** ISO date string "YYYY-MM-DD" (maps to C# DateOnly). */
export type DateOnlyString = string

export interface Gerbil {
  id: string
  name: string
  gender: Gender
  status: GerbilStatus
  dateOfBirth: DateOnlyString | null
  dateOfDeath: DateOnlyString | null
  causeOfDeath: string | null
  goHomeDate: DateOnlyString | null
  litterId: string | null
  enclosureId: string | null
  colorVarietyId: string | null
  originContactId: string | null
  receiverContactId: string | null
  /** SEARCH-1/2b: free-text Herkunft (Züchter) from the import; Gridify-filterable. */
  originBreeder?: string | null
  /**
   * SEARCH-1/2b: normalized name (lowercase, [\s._-] stripped) — filter-only,
   * not part of the returned payload; present here so it can be a Gridify field.
   */
  nameSearch?: string | null
  /** Compact GEN-1 genotype string, e.g. "Aa CC Dd EE GG Pp Spsp rere" (or "?"-wildcards). */
  genotype: string | null
  notes: string | null
  /**
   * FEAT-14: Charakterbogen. Selected trait KEYS (see de.character.traits).
   * Optional until FEAT-14a backend exposes the fields; treat absent as [].
   */
  characterTraits?: string[] | null
  characterNote?: string | null
  /**
   * Residency (Bestand): true = part of the own clan (Kleine Chaoten), false =
   * external/pedigree-only ancestor imported for the Stammbaum. Gridify-filterable
   * (`isResident==true`); the Tiere list defaults to resident-only. Absent = treat
   * as resident (backend default true).
   */
  isResident?: boolean
  /** FORM-FIELDS-1: true=gehörlos, false=hörend, null=unbekannt. */
  isDeaf?: boolean | null
}

/** Payload for POST /gerbils. */
export interface CreateGerbil {
  name: string
  gender: Gender
  status?: GerbilStatus
  dateOfBirth?: DateOnlyString | null
  dateOfDeath?: DateOnlyString | null
  causeOfDeath?: string | null
  goHomeDate?: DateOnlyString | null
  litterId?: string | null
  enclosureId?: string | null
  colorVarietyId?: string | null
  originContactId?: string | null
  receiverContactId?: string | null
  originBreeder?: string | null
  genotype?: string | null
  notes?: string | null
  characterTraits?: string[] | null
  characterNote?: string | null
  isResident?: boolean
  isDeaf?: boolean | null
}

/** Payload for PUT /gerbils/{id} (all optional / partial update). */
export type UpdateGerbil = Partial<CreateGerbil>

export interface ColorVariety {
  id: string
  name: string
  canonicalGenotype: string | null
  sortOrder: number
}

export interface Enclosure {
  id: string
  name: string
  notes: string | null
}

export interface Contact {
  id: string
  name: string
  email: string | null
  phone: string | null
  address: string | null
  notes: string | null
}

export interface Litter {
  id: string
  name: string
  /** Wurfdatum (birth date). */
  date: DateOnlyString
  /** Wurfstärke — total born count. */
  totalBorn: number | null
  /**
   * Abgabedatum (auto-suggested ~35 days after birth, editable).
   * Optional in the type so existing Litter constructors (e.g. pedigree test
   * factories) keep compiling; the API DTO always includes it (nullable).
   */
  expectedGoHomeDate?: DateOnlyString | null
  notes?: string | null
  fatherId: string | null
  motherId: string | null
}

/** Payload for POST /litters. */
export interface CreateLitter {
  name: string
  date: DateOnlyString
  totalBorn?: number | null
  expectedGoHomeDate?: DateOnlyString | null
  notes?: string | null
  fatherId?: string | null
  motherId?: string | null
}

export type UpdateLitter = Partial<CreateLitter>

/** Paged list envelope returned by Gridify list endpoints. */
export interface Paged<T> {
  items: T[]
  totalCount: number
  page: number
  pageSize: number
}
