/**
 * Badge/indicator utilities for public-facing cards.
 * Pure functions — take entity data, return booleans.
 */

const NEW_THRESHOLD_HOURS = 48;
const TRENDING_EMAIL_THRESHOLD = 50;
const ALMOST_FULL_RATIO = 0.75;

/** Campaign is "trending" if admin-highlighted OR has many emails */
export function isTrending(campaign: {
  highlightCampaign?: boolean;
  _count?: { emails?: number };
}): boolean {
  if (campaign.highlightCampaign) return true;
  return (campaign._count?.emails ?? 0) >= TRENDING_EMAIL_THRESHOLD;
}

/** Shift is almost full (> 75% capacity) */
export function isAlmostFull(shift: {
  currentVolunteers: number;
  maxVolunteers: number;
}): boolean {
  if (shift.maxVolunteers <= 0) return false;
  return shift.currentVolunteers / shift.maxVolunteers >= ALMOST_FULL_RATIO;
}

/** Entity was created within the last 48 hours */
export function isNew(createdAt: string | Date): boolean {
  const created = typeof createdAt === 'string' ? new Date(createdAt) : createdAt;
  const hoursAgo = (Date.now() - created.getTime()) / (1000 * 60 * 60);
  return hoursAgo <= NEW_THRESHOLD_HOURS;
}
