import type { GermplasmAttribute, GermplasmAttributeValue } from "@/lib/api/types.gen";
import { NONE_SELECT_VALUE, type SelectOption } from "./types";

export { NONE_SELECT_VALUE, type SelectOption };

export type AttributeDataType = "Code" | "Date" | "Duration" | "Nominal" | "Numerical" | "Ordinal" | "Text";

export const ATTRIBUTE_DATA_TYPE_OPTIONS: SelectOption[] = [
  { value: "Text", label: "Text 文本" },
  { value: "Numerical", label: "Numerical 数值" },
  { value: "Nominal", label: "Nominal 名义分类" },
  { value: "Ordinal", label: "Ordinal 有序分类" },
  { value: "Code", label: "Code 编码" },
  { value: "Date", label: "Date 日期" },
  { value: "Duration", label: "Duration 时长" },
];

export interface AttributeRecord {
  id: string;
  attributeDbId: string;
  attributeName: string | null;
  attributeCategory: string | null;
  attributeDescription: string | null;
  commonCropName: string | null;
  crop_id: string | null;
  dataType: AttributeDataType | null;
  attributePUI: string | null;
}

export interface AttributeValueRecord {
  id: string;
  attributeValueDbId: string;
  attributeDbId: string | null;
  attribute_id: string | null;
  attributeName: string | null;
  germplasmDbId: string | null;
  germplasm_id: string | null;
  germplasmName: string | null;
  value: string | null;
  determinedDate: string | null;
  determined_date: string | null;
}

export const readAttributeDataType = (attribute: GermplasmAttribute): AttributeDataType | null => {
  const fromScale = attribute.scale?.dataType;
  if (fromScale) return fromScale as AttributeDataType;
  return null;
};
