import { MappedSkill, SkillApiItem } from "../types/skills.type";

/**
 * Converts a raw API skill array → MappedSkill[] for CustomTextbox options.
 * Pure — easy to unit-test.
 */
export function mapSkills(items: SkillApiItem[] = []): MappedSkill[] {
  return items
    .filter(
      (s): s is SkillApiItem & { type: string } => typeof s.type === "string",
    )
    .map((skill) => ({
      id: skill.id,
      uuid: skill.uuid,
      label: skill.name ?? "",
      type: normalizeSkillType(skill.type),
    }));
}
function normalizeSkillType(type: string): "soft" | "tool" | "language" {
  if (type === "tools") return "tool";

  if (type === "language") return "language";

  return type as "soft" | "tool" | "language";
}
