/**
 * Practice-area constants for the precedent library.
 *
 * The chair confined the library to the three appeals committee
 * domains — no national-insurance corpus. The DB enforces this
 * via a CHECK constraint on case_law.practice_area.
 */

export const PRACTICE_AREAS = [
  { value: "rishuy_uvniya", label: "רישוי ובניה", short: "רישוי" },
  { value: "betterment_levy", label: "היטל השבחה", short: "השבחה" },
  { value: "compensation_197", label: "פיצויים לפי ס' 197", short: "פיצויים" },
] as const;

export const PRECEDENT_LEVELS = [
  { value: "עליון", label: "עליון" },
  { value: "מנהלי", label: "מנהלי" },
  { value: "ועדת_ערר_ארצית", label: "ועדת ערר ארצית" },
  { value: "ועדת_ערר_מחוזית", label: "ועדת ערר מחוזית" },
] as const;

export const SOURCE_TYPES = [
  { value: "court_ruling", label: "פסק דין" },
  { value: "appeals_committee", label: "החלטת ועדת ערר" },
] as const;

/**
 * Districts for ועדות ערר. The chair's committee is ירושלים; the rest
 * are listed so that uploaded precedents from peer committees can be
 * filed correctly. Order matches what's displayed in the UI dropdown.
 */
export const DISTRICTS = [
  { value: "ירושלים", label: "ירושלים" },
  { value: "מרכז", label: "מרכז" },
  { value: "תל אביב", label: "תל אביב" },
  { value: "צפון", label: "צפון" },
  { value: "דרום", label: "דרום" },
  { value: "חיפה", label: "חיפה" },
  { value: "ארצי", label: "ארצי" },
] as const;

export function practiceAreaLabel(value: string | null | undefined): string {
  if (!value) return "—";
  const match = PRACTICE_AREAS.find((p) => p.value === value);
  return match ? match.label : value;
}

export function practiceAreaShort(value: string | null | undefined): string {
  if (!value) return "—";
  const match = PRACTICE_AREAS.find((p) => p.value === value);
  return match ? match.short : value;
}

/**
 * Display label for ``appeal_subtype``. The field is free text — the chair
 * usually types specific subjects like "תכנית רחביה" or "סופיות ההחלטה" —
 * but the LLM extractor sometimes mistakenly stuffs the practice_area
 * enum value (``betterment_levy``, ``rishuy_uvniya``, ``compensation_197``)
 * in there. When that happens, translate to Hebrew so the UI doesn't
 * leak English. Otherwise return the value unchanged.
 */
export function appealSubtypeLabel(value: string | null | undefined): string {
  if (!value) return "";
  const enumMatch = PRACTICE_AREAS.find((p) => p.value === value);
  return enumMatch ? enumMatch.label : value;
}
