import type { ListDetails, ListNewRequest } from "@/lib/api/types.gen";

export const NONE_SELECT_VALUE = "__none__";

export type ListType = NonNullable<ListNewRequest["listType"]>;

export type ListRecord = ListDetails & {
  id: string;
  list_name?: string | null;
  list_description?: string | null;
  list_source?: string | null;
  list_owner_name?: string | null;
  list_owner_person_id?: string | null;
  list_type?: ListType | null;
  date_created?: string | null;
  date_modified?: string | null;
};

export type SelectOption = {
  value: string;
  label: string;
};

export const LIST_TYPE_OPTIONS: Array<{ value: ListType; label: string }> = [
  { value: "germplasm", label: "种质 (germplasm)" },
  { value: "markers", label: "标记 (markers)" },
  { value: "programs", label: "项目 (programs)" },
  { value: "trials", label: "试验 (trials)" },
  { value: "studies", label: "研究 (studies)" },
  { value: "observationUnits", label: "观测单元 (observationUnits)" },
  { value: "observations", label: "观测值 (observations)" },
  { value: "observationVariables", label: "观测变量 (observationVariables)" },
  { value: "samples", label: "样品 (samples)" },
];

export function listTypeLabel(type: unknown): string {
  const normalized = String(type ?? "").trim();
  const matched = LIST_TYPE_OPTIONS.find((option) => option.value === normalized);
  return matched?.label ?? (normalized || "—");
}
