export interface CpuPreset {
  model: string
  vendor: "Intel" | "AMD"
  family: "Xeon E5" | "Xeon Platinum" | "Xeon Gold" | "EPYC" | "Ryzen"
  baseMhz: number
  turboMhz: number
}

export const CPU_PRESETS: CpuPreset[] = [
  { model: "Xeon E5-2680 v3", vendor: "Intel", family: "Xeon E5", baseMhz: 2500, turboMhz: 3300 },
  { model: "Xeon E5-2680 v4", vendor: "Intel", family: "Xeon E5", baseMhz: 2400, turboMhz: 3300 },
  { model: "Xeon E5-2683 v4", vendor: "Intel", family: "Xeon E5", baseMhz: 2100, turboMhz: 3000 },
  { model: "Xeon E5-2690 v4", vendor: "Intel", family: "Xeon E5", baseMhz: 2600, turboMhz: 3500 },
  { model: "Xeon E5-2696 v4", vendor: "Intel", family: "Xeon E5", baseMhz: 2200, turboMhz: 3700 },
  { model: "Xeon E5-2697 v4", vendor: "Intel", family: "Xeon E5", baseMhz: 2300, turboMhz: 3600 },

  { model: "Xeon Platinum 8255C", vendor: "Intel", family: "Xeon Platinum", baseMhz: 2500, turboMhz: 3100 },
  { model: "Xeon Platinum 8269CY", vendor: "Intel", family: "Xeon Platinum", baseMhz: 2500, turboMhz: 3200 },
  { model: "Xeon Platinum 8358", vendor: "Intel", family: "Xeon Platinum", baseMhz: 2600, turboMhz: 3400 },
  { model: "Xeon Platinum 8369B", vendor: "Intel", family: "Xeon Platinum", baseMhz: 2700, turboMhz: 3500 },
  { model: "Xeon Platinum 8375C", vendor: "Intel", family: "Xeon Platinum", baseMhz: 2900, turboMhz: 3500 },

  { model: "Xeon Gold 6133", vendor: "Intel", family: "Xeon Gold", baseMhz: 2500, turboMhz: 3700 },
  { model: "Xeon Gold 6248R", vendor: "Intel", family: "Xeon Gold", baseMhz: 3000, turboMhz: 4000 },
  { model: "Xeon Gold 6338", vendor: "Intel", family: "Xeon Gold", baseMhz: 2000, turboMhz: 3200 },

  { model: "AMD EPYC 7402", vendor: "AMD", family: "EPYC", baseMhz: 2800, turboMhz: 3350 },
  { model: "AMD EPYC 7502", vendor: "AMD", family: "EPYC", baseMhz: 2500, turboMhz: 3350 },
  { model: "AMD EPYC 7542", vendor: "AMD", family: "EPYC", baseMhz: 2900, turboMhz: 3400 },
  { model: "AMD EPYC 7713", vendor: "AMD", family: "EPYC", baseMhz: 2000, turboMhz: 3675 },
  { model: "AMD EPYC 9654", vendor: "AMD", family: "EPYC", baseMhz: 2400, turboMhz: 3700 },
  { model: "AMD EPYC 9754", vendor: "AMD", family: "EPYC", baseMhz: 2250, turboMhz: 3100 },

  { model: "AMD Ryzen 9 5950X", vendor: "AMD", family: "Ryzen", baseMhz: 3400, turboMhz: 4900 },
  { model: "AMD Ryzen 9 7950X", vendor: "AMD", family: "Ryzen", baseMhz: 4500, turboMhz: 5700 },
]

export function findCpuPreset(model: string | null | undefined): CpuPreset | null {
  if (!model) return null
  const norm = model.trim().toLowerCase()
  return CPU_PRESETS.find((p) => p.model.toLowerCase() === norm) ?? null
}

export function formatGhz(mhz: number | null | undefined): string {
  if (!mhz || mhz <= 0) return ""
  return (mhz / 1000).toFixed(mhz % 1000 === 0 ? 1 : 2) + " GHz"
}
