export const MISSING_FACT = "missing";
export const UNKNOWN_FACT = "unknown";

export function isBlank(value: string | undefined | null): boolean {
  return !value || !value.trim();
}

export function isPresentFact(value: string | undefined | null): boolean {
  const t = value?.trim() ?? "";
  if (!t) return false;
  if (t === MISSING_FACT || t === UNKNOWN_FACT) return false;
  return true;
}

export function presentOrMissing(value: string | undefined | null): string {
  const t = value?.trim() ?? "";
  return t || MISSING_FACT;
}

export function presentOrUnknown(value: string | undefined | null): string {
  const t = value?.trim() ?? "";
  return t || UNKNOWN_FACT;
}

export function uniqueNonEmpty(values: Array<string | undefined | null>, limit = 12): string[] {
  const seen = new Set<string>();
  const out: string[] = [];
  for (const raw of values) {
    const t = raw?.trim() ?? "";
    if (!isPresentFact(t)) continue;
    const key = t.toLowerCase();
    if (seen.has(key)) continue;
    seen.add(key);
    out.push(t);
    if (out.length >= limit) break;
  }
  return out;
}
