// src/lib/backlink/relevance.ts — pertinence d'une source pour un site (pur).
// v1 : langue × force (DR sinon DA). Le terme thématique s'ajoutera quand
// link_sources.themes et un thème de site existeront (CdC backlink/recherche F3).

const LANG_MISMATCH_FACTOR = 0.3;
export const FOOTPRINT_THRESHOLD = 3;

export function relevanceScore(
  source: { language: string; dr: number | null; da: number | null },
  siteLanguage: string,
): number {
  const langMatch = source.language === siteLanguage ? 1 : LANG_MISMATCH_FACTOR;
  const strength = source.dr ?? source.da ?? 0;
  return Math.round(langMatch * strength * 10) / 10;
}

/** F5 — alerte quand la source référence déjà N sites de l'org. */
export function footprintAlert(siteCount: number): boolean {
  return siteCount >= FOOTPRINT_THRESHOLD;
}
