export type ConversionTier = "completed" | "intent" | "signal";

export const CONVERSION_TIERS: Record<string, ConversionTier> = {
  // Completed - definitive conversion actions
  form_submitted: "completed",
  form_submission: "completed",
  form_submit: "completed",
  phone_call: "completed",
  click_to_call: "completed",
  phone_number_click: "completed",
  appointment_booked: "completed",
  booking_confirmed: "completed",
  calendly: "completed",
  file_download: "completed",
  email_contact: "completed",
  email_click: "completed",
  sms_contact: "completed",
  sms_click: "completed",
  sms_optin: "completed",
  sms_community_join: "completed",
  purchase: "completed",
  newsletter_signup: "completed",
  waitlist_signup: "completed",

  // Intent - started a conversion flow but did not complete
  appointment_attempted: "intent",
  appointment_intent: "intent",
  form_filled: "intent",
  form_started: "intent",
  booking_attempted: "intent",
  booking_attempt: "intent",
  add_to_cart: "intent",
  checkout_started: "intent",
  chat_initiated: "intent",
  booking_submit: "intent",
  sms_keyword_displayed: "intent",
  sms_outbound_click: "intent",
  sms_optin_followup: "intent",
  phone_field_completed: "intent",

  // Signal - engagement only, not a conversion flow
  phone_input: "signal",
  phone_copy: "signal",
  form_iframe_present: "signal",
};

export const DEFAULT_COUNTED_TIERS: ConversionTier[] = ["completed"];

export function getDefaultTier(conversionType: string): ConversionTier | "unknown" {
  return CONVERSION_TIERS[conversionType] ?? "unknown";
}

export const TIER_LABELS: Record<ConversionTier, string> = {
  completed: "Completed Conversions",
  intent: "Intent Signals",
  signal: "Engagement Signals",
};

export const TIER_DESCRIPTIONS: Record<ConversionTier, string> = {
  completed: "Visitors who completed a conversion action (form submit, phone call, booking).",
  intent: "Visitors who started a conversion flow but did not finish.",
  signal: "Engagement events showing interest but not a conversion.",
};

export function humanizeType(conversionType: string): string {
  return conversionType
    .replace(/_/g, " ")
    .replace(/\b\w/g, (c) => c.toUpperCase());
}
