import { OwnPostPerformanceItem } from "../api/haixun";

export function postEngagementScore(post: OwnPostPerformanceItem): number {
  return post.like_count + post.reply_count * 2 + (post.views ?? 0) / 80 + (post.repost_count ?? 0) * 3;
}

export function isStrongPost(post: OwnPostPerformanceItem, peers: OwnPostPerformanceItem[]): boolean {
  const score = postEngagementScore(post);
  if (score < 8) return false;
  if (peers.length <= 1) return score >= 12;
  const sorted = [...peers].map(postEngagementScore).sort((a, b) => a - b);
  const median = sorted[Math.floor(sorted.length / 2)] ?? 0;
  return score >= Math.max(median * 1.2, 12);
}