import type { WorkerData } from "../types";

export function generateBio(data: WorkerData): string {
  const tradeStr = data.trades.join(" and ");
  const expStr =
    data.experience === 0
      ? "under 1 year"
      : data.experience >= 12
        ? "10+ years"
        : `${data.experience} years`;
  const certStr =
    data.certifications.length > 0
      ? ` Holds ${data.certifications.join(", ")}.`
      : "";

  return `Experienced ${tradeStr.toLowerCase()} with ${expStr} in the construction industry. Based in ${data.suburb}, available for ${data.availability} work.${certStr}`;
}

export function findClosestExperience(experienceYears: number): number {
  const EXPERIENCE_OPTIONS = [
    { label: "Less than 1 year", value: 0 },
    { label: "1-3 years", value: 2 },
    { label: "3-5 years", value: 4 },
    { label: "5-10 years", value: 7 },
    { label: "10+ years", value: 12 },
  ] as const;
  
  return EXPERIENCE_OPTIONS.reduce((prev, curr) =>
    Math.abs(curr.value - experienceYears) < Math.abs(prev.value - experienceYears) ? curr : prev
  ).value;
}