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: await uuidv5(NS, "unit:kg"),
  g: await uuidv5(NS, "unit:g"),
  lb: await uuidv5(NS, "unit:lb"),
  oz: await uuidv5(NS, "unit:oz"),
  m: await uuidv5(NS, "unit:m"),
  cm: await uuidv5(NS, "unit:cm"),
  ft: await uuidv5(NS, "unit:ft"),
  in: await uuidv5(NS, "unit:in"),
  L: await uuidv5(NS, "unit:L"),
  mL: await uuidv5(NS, "unit:mL"),
  gal: await uuidv5(NS, "unit:gal"),
  sqm: await uuidv5(NS, "unit:sqm"),
  sqft: await uuidv5(NS, "unit:sqft"),
  hr: await uuidv5(NS, "unit:hr"),
  min: await uuidv5(NS, "unit:min"),
  s: await uuidv5(NS, "unit:s"),
  ea: await uuidv5(NS, "unit:ea"),
  dz: await uuidv5(NS, "unit:dz"),
  pk: await 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, status: "ACTIVE" as const },
  [unitIds.g]: { name: "Gram", symbol: "g", categoryId: uomCategoryIds.Weight, conversionFactor: 0.001, roundingPrecision: 0, status: "ACTIVE" as const },
  [unitIds.lb]: { name: "Pound", symbol: "lb", categoryId: uomCategoryIds.Weight, conversionFactor: 0.453592, roundingPrecision: 2, status: "ACTIVE" as const },
  [unitIds.oz]: { name: "Ounce", symbol: "oz", categoryId: uomCategoryIds.Weight, conversionFactor: 0.0283495, roundingPrecision: 2, status: "ACTIVE" as const },

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

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

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

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

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