/**
 * Active Conversion Filter
 * ────────────────────────
 * Standard Prisma WHERE clause fragment for SiteConversion queries
 * that should only count REAL, UNIQUE conversions.
 *
 * Excludes:
 *   - isDuplicateOf != null (duplicate of another row, from dedup cron)
 *   - invalidatedReason != null (deprecated detection method, forensic-only)
 *
 * Use this in EVERY analytics/reporting query that touches
 * SiteConversion so we never accidentally include inflated counts.
 *
 * Admin/debug queries that need ALL rows should NOT use this filter.
 */

export const ACTIVE_CONVERSION_FILTER = {
  isDuplicateOf: null,
  invalidatedReason: null,
} as const;

/**
 * Merge the active filter into an existing Prisma where clause.
 * Convenience for queries that already have their own conditions.
 */
export function withActiveFilter<T extends Record<string, unknown>>(where: T): T & typeof ACTIVE_CONVERSION_FILTER {
  return { ...where, ...ACTIVE_CONVERSION_FILTER };
}
