export const DOCTOR_TAG_MAX_COUNT = 20
export const DOCTOR_TAG_MAX_LENGTH = 40

export function parseDoctorTagsFromBody(value: unknown): string[] {
  if (!Array.isArray(value)) return []
  const out: string[] = []
  const seen = new Set<string>()

  for (const raw of value) {
    if (typeof raw !== "string") continue
    const normalized = raw.trim().replace(/\s+/g, " ")
    if (!normalized) continue
    if (normalized.length > DOCTOR_TAG_MAX_LENGTH) continue
    const key = normalized.toLowerCase()
    if (seen.has(key)) continue
    seen.add(key)
    out.push(normalized)
    if (out.length >= DOCTOR_TAG_MAX_COUNT) break
  }

  return out
}
