/** 物理/业务维度：同维度内可通过 factor_to_base 换算 */
export type UnitDimension =
  | "mass"
  | "area"
  | "length"
  | "volume"
  | "count"
  | "package"
  | "yield"
  | "application_rate_mass"
  | "application_rate_volume"
  | "plant_density"
  | "water_depth"
  | "percent"
  | "scale";

export type UnitCategory =
  | "mass"
  | "area"
  | "length"
  | "volume"
  | "count"
  | "package"
  | "yield"
  | "application_rate"
  | "plant_density"
  | "water"
  | "percent"
  | "scale";

export type UnitDefinition = {
  id: string;
  unitCode: string;
  ucumCode?: string;
  nameZh: string;
  symbol: string;
  unitCategory: UnitCategory;
  dimension: UnitDimension;
  /** 同维度基准单位 code */
  baseUnitCode?: string;
  /** base_value = value × factor_to_base + offset_to_base */
  factorToBase?: number;
  offsetToBase?: number;
  isConvertible: boolean;
  isRequiredSpec: boolean;
  isActive?: boolean;
};

export type ConvertResult =
  | { ok: true; value: number; baseValue: number }
  | { ok: false; reason: "missing_factor" | "different_dimension" | "not_convertible" | "invalid_value" };

export type SeedCountConvertResult =
  | { ok: true; value: number }
  | { ok: false; reason: "missing_tkw" | "invalid_value" | "invalid_tkw" };
