/**
 * Compliance constants + helpers
 * ──────────────────────────────
 * Centralises the platform default retention period + per-brand
 * resolution so the data-retention cron, the Compliance dashboard,
 * and any future reporting all read from one place.
 */

/** Platform default retention in days. 13 months — matches GA4's
 *  default cap so customers migrating from GA4 don't see a sudden
 *  retention regression. */
export const PLATFORM_RETENTION_DAYS = 395;

export interface RetentionContext {
  dataRetentionDays: number | null;
}

/** Resolve the effective retention period (in days) for a brand. */
export function effectiveRetentionDays(ctx: RetentionContext): number {
  return ctx.dataRetentionDays ?? PLATFORM_RETENTION_DAYS;
}

/** Compute the cutoff Date — rows with timestamp/createdAt <
 *  cutoff are eligible for purge. */
export function retentionCutoff(ctx: RetentionContext, now: Date = new Date()): Date {
  const days = effectiveRetentionDays(ctx);
  return new Date(now.getTime() - days * 86_400_000);
}

/** Healthcare keywords — used for "is this brand likely healthcare?"
 *  detection so the Compliance dashboard can flag brands that
 *  should have healthcareMode enabled. */
const HEALTHCARE_INDUSTRY_KEYWORDS = [
  "healthcare", "health care", "medical", "clinic", "hospital",
  "physician", "doctor", "dental", "dentist", "cardiology",
  "vascular", "pediatric", "dermatology", "orthopedic", "psychiatry",
  "therapy", "wellness", "rehabilitation", "surgery", "imaging",
  "radiology", "oncology", "pharmacy",
];
export function isLikelyHealthcare(industry: string | null | undefined): boolean {
  if (!industry) return false;
  const lower = industry.toLowerCase();
  return HEALTHCARE_INDUSTRY_KEYWORDS.some((k) => lower.includes(k));
}
