/**
 * Canonical document tagging metadata. Mirrors web/app.py:DOC_TYPE_NAMES and
 * the validation lists in mcp-server/src/legal_mcp/tools/documents.py.
 *
 * If you add a doc_type or appraiser_side here, add the matching value on the
 * backend too — the API rejects anything not on its whitelist.
 */

export type DocType =
  | "appeal"
  | "response"
  | "protocol"
  | "plan"
  | "decision"
  | "court_decision"
  | "permit"
  | "appraisal"
  | "exhibit"
  | "objection"
  | "reference";

export const DOC_TYPE_LABELS: Record<DocType, string> = {
  appeal:         "כתב ערר",
  response:       "כתב תשובה",
  protocol:       "פרוטוקול",
  plan:           "תכנית",
  decision:       "החלטת ועדה מקומית",
  court_decision: "פסק דין",
  permit:         "היתר",
  appraisal:      "שומה",
  exhibit:        "נספח",
  objection:      "התנגדות",
  reference:      "חומר רקע",
};

/** Display order for editors and selects. */
export const DOC_TYPE_OPTIONS: { value: DocType; label: string }[] = [
  { value: "appeal",         label: DOC_TYPE_LABELS.appeal },
  { value: "response",       label: DOC_TYPE_LABELS.response },
  { value: "protocol",       label: DOC_TYPE_LABELS.protocol },
  { value: "plan",           label: DOC_TYPE_LABELS.plan },
  { value: "decision",       label: DOC_TYPE_LABELS.decision },
  { value: "court_decision", label: DOC_TYPE_LABELS.court_decision },
  { value: "permit",         label: DOC_TYPE_LABELS.permit },
  { value: "appraisal",      label: DOC_TYPE_LABELS.appraisal },
  { value: "exhibit",        label: DOC_TYPE_LABELS.exhibit },
  { value: "objection",      label: DOC_TYPE_LABELS.objection },
  { value: "reference",      label: DOC_TYPE_LABELS.reference },
];

export function doctypeLabel(value: string): string {
  return (DOC_TYPE_LABELS as Record<string, string>)[value] ?? value;
}

export function doctypeTone(value: string): string {
  switch (value) {
    case "appeal":         return "bg-info-bg text-info border-info/40";
    case "response":       return "bg-gold-wash text-gold-deep border-gold/40";
    case "decision":       return "bg-success-bg text-success border-success/40";
    case "protocol":       return "bg-warn-bg text-warn border-warn/40";
    case "appraisal":      return "bg-info-bg text-info border-info/40";
    case "court_decision": return "bg-success-bg text-success border-success/40";
    default:               return "bg-rule-soft text-ink-muted border-rule";
  }
}

// ── Appraiser sides (only relevant when doc_type === "appraisal") ──

export type AppraiserSide = "committee" | "appellant" | "deciding";

export const APPRAISER_SIDE_LABELS: Record<AppraiserSide, string> = {
  committee: "שמאי הוועדה המקומית",
  appellant: "שמאי העורר",
  deciding:  "שמאי מכריע",
};

export const APPRAISER_SIDE_OPTIONS: { value: AppraiserSide; label: string }[] = [
  { value: "committee", label: APPRAISER_SIDE_LABELS.committee },
  { value: "appellant", label: APPRAISER_SIDE_LABELS.appellant },
  { value: "deciding",  label: APPRAISER_SIDE_LABELS.deciding },
];

export function appraiserSideLabel(value: string): string {
  return (APPRAISER_SIDE_LABELS as Record<string, string>)[value] ?? value;
}
