export const UNIT_MILLILITER = 'mL'
export const UNIT_LITER = 'L'
export const UNIT_GALLON = 'gal'

export const LITER_TO_MILLILITER = 1000
export const GALLON_TO_MILLILITER = 3785.411784

export const UNIT_RATIOS = {
  mL: {
    mL: 1,
    L: 1 / LITER_TO_MILLILITER,
    gal: 1 / GALLON_TO_MILLILITER
  },
  L: {
    mL: LITER_TO_MILLILITER,
    L: 1,
    gal: LITER_TO_MILLILITER / GALLON_TO_MILLILITER
  },
  gal: {
    mL: GALLON_TO_MILLILITER,
    L: 1 / (LITER_TO_MILLILITER / GALLON_TO_MILLILITER),
    gal: 1
  }
}

export function convertMixMaterialQuantity(computedQuantity: { percents: boolean, quantity: number }, from: string, to: string): number {
  return !computedQuantity.percents ? convertQuantity(computedQuantity.quantity, from, to) : computedQuantity.quantity
}

export function convertQuantity(quantity: number, from: string, to: string): number {
  return quantity * UNIT_RATIOS[from][to]
}
