import { validateHumanWriting } from "../validators/human-validator";

/** 0–100 human-writing quality estimate. */
export function scoreHumanWriting(text: string): number {
  const validation = validateHumanWriting(text);
  let score = 85;
  score -= validation.clichéCount * 8;
  if (text.length >= 250 && text.length <= 2200) score += 5;
  if (text.includes("**")) score += 3;
  const questions = (text.match(/\?/g) ?? []).length;
  if (questions >= 1) score += 2;
  return Math.max(0, Math.min(100, score));
}

export function scoreEmotionAlignment(text: string, emotions: string[]): number {
  const lower = text.toLowerCase();
  const hits = emotions.filter((e) => lower.includes(e.toLowerCase())).length;
  const base = 70 + hits * 6;
  return Math.min(100, base);
}

export function scoreEngagement(text: string): number {
  const base = 77;
  const hashtagBonus = (text.match(/#/g) ?? []).length * 3;
  const lengthBonus = text.length > 400 && text.length < 2200 ? 12 : 0;
  return Math.min(98, base + hashtagBonus + lengthBonus);
}
