import { uuidv5 } from "../../../shared/uuidv5";
import type { UnitCreate, Schema } from "../lib/types";
import { uomCategoryIds } from "./uomCategories";

const NS = "erp-kit:primitives";

type SeedRow = Omit<UnitCreate<Schema>, "id">;

export const unitIds = {
  kg: uuidv5(NS, "unit:kg"),
  g: uuidv5(NS, "unit:g"),
  lb: uuidv5(NS, "unit:lb"),
  oz: uuidv5(NS, "unit:oz"),
  m: uuidv5(NS, "unit:m"),
  cm: uuidv5(NS, "unit:cm"),
  ft: uuidv5(NS, "unit:ft"),
  in: uuidv5(NS, "unit:in"),
  L: uuidv5(NS, "unit:L"),
  mL: uuidv5(NS, "unit:mL"),
  gal: uuidv5(NS, "unit:gal"),
  sqm: uuidv5(NS, "unit:sqm"),
  sqft: uuidv5(NS, "unit:sqft"),
  hr: uuidv5(NS, "unit:hr"),
  min: uuidv5(NS, "unit:min"),
  s: uuidv5(NS, "unit:s"),
  ea: uuidv5(NS, "unit:ea"),
  dz: uuidv5(NS, "unit:dz"),
  pk: uuidv5(NS, "unit:pk"),
} as const;

export const units: Record<string, SeedRow> = {
  // Weight (reference: kg = 1.0)
  [unitIds.kg]: { name: "Kilogram", symbol: "kg", categoryId: uomCategoryIds.Weight, conversionFactor: 1, roundingPrecision: 2, isActive: true },
  [unitIds.g]: { name: "Gram", symbol: "g", categoryId: uomCategoryIds.Weight, conversionFactor: 0.001, roundingPrecision: 0, isActive: true },
  [unitIds.lb]: { name: "Pound", symbol: "lb", categoryId: uomCategoryIds.Weight, conversionFactor: 0.453592, roundingPrecision: 2, isActive: true },
  [unitIds.oz]: { name: "Ounce", symbol: "oz", categoryId: uomCategoryIds.Weight, conversionFactor: 0.0283495, roundingPrecision: 2, isActive: true },

  // Length (reference: m = 1.0)
  [unitIds.m]: { name: "Meter", symbol: "m", categoryId: uomCategoryIds.Length, conversionFactor: 1, roundingPrecision: 2, isActive: true },
  [unitIds.cm]: { name: "Centimeter", symbol: "cm", categoryId: uomCategoryIds.Length, conversionFactor: 0.01, roundingPrecision: 0, isActive: true },
  [unitIds.ft]: { name: "Foot", symbol: "ft", categoryId: uomCategoryIds.Length, conversionFactor: 0.3048, roundingPrecision: 2, isActive: true },
  [unitIds.in]: { name: "Inch", symbol: "in", categoryId: uomCategoryIds.Length, conversionFactor: 0.0254, roundingPrecision: 2, isActive: true },

  // Volume (reference: L = 1.0)
  [unitIds.L]: { name: "Liter", symbol: "L", categoryId: uomCategoryIds.Volume, conversionFactor: 1, roundingPrecision: 2, isActive: true },
  [unitIds.mL]: { name: "Milliliter", symbol: "mL", categoryId: uomCategoryIds.Volume, conversionFactor: 0.001, roundingPrecision: 0, isActive: true },
  [unitIds.gal]: { name: "Gallon", symbol: "gal", categoryId: uomCategoryIds.Volume, conversionFactor: 3.78541, roundingPrecision: 2, isActive: true },

  // Area (reference: m² = 1.0)
  [unitIds.sqm]: { name: "Square Meter", symbol: "m²", categoryId: uomCategoryIds.Area, conversionFactor: 1, roundingPrecision: 2, isActive: true },
  [unitIds.sqft]: { name: "Square Foot", symbol: "ft²", categoryId: uomCategoryIds.Area, conversionFactor: 0.092903, roundingPrecision: 2, isActive: true },

  // Time (reference: hr = 1.0)
  [unitIds.hr]: { name: "Hour", symbol: "hr", categoryId: uomCategoryIds.Time, conversionFactor: 1, roundingPrecision: 2, isActive: true },
  [unitIds.min]: { name: "Minute", symbol: "min", categoryId: uomCategoryIds.Time, conversionFactor: 1 / 60, roundingPrecision: 0, isActive: true },
  [unitIds.s]: { name: "Second", symbol: "s", categoryId: uomCategoryIds.Time, conversionFactor: 1 / 3600, roundingPrecision: 0, isActive: true },

  // Quantity (reference: ea = 1.0)
  [unitIds.ea]: { name: "Each", symbol: "ea", categoryId: uomCategoryIds.Quantity, conversionFactor: 1, roundingPrecision: 0, isActive: true },
  [unitIds.dz]: { name: "Dozen", symbol: "dz", categoryId: uomCategoryIds.Quantity, conversionFactor: 12, roundingPrecision: 0, isActive: true },
  [unitIds.pk]: { name: "Pack", symbol: "pk", categoryId: uomCategoryIds.Quantity, conversionFactor: 1, roundingPrecision: 0, isActive: true },
};
