// ─── Industry Benchmark Data ──────────────────────────────────────────────────
// All values are ESTIMATES based on industry research aggregates.
// avgCustomerValue and avgConversionRate are directional baselines used for
// Lost Opportunity Calculator estimates ONLY — not customer-specific measurements.
// Sources: HubSpot, WordStream, Ruler Analytics, First Page Sage industry reports (2023-2024).

export interface IndustryBenchmarkData {
  avgDomainAuthority: number;     // avg referring domains for industry
  avgReferringDomains: number;    // same as avgDomainAuthority (kept for clarity)
  avgBacklinks: number;
  avgAiOverviewCitationRate: number;  // 0-1, fraction of audits where brand appears in AI Overview
  avgPageCount: number;
  avgSchemaCoverage: number;      // 0-1, fraction of pages with valid schema
  p25DomainAuthority: number;
  p75DomainAuthority: number;
  sampleSize: "rough_estimate";
  // Lost Opportunity Calculator inputs — directional estimates, not measurements
  avgCustomerValue: number;       // avg revenue per customer/conversion in USD
  avgConversionRate: number;      // decimal, e.g. 0.038 = 3.8% web visitor conversion rate
  sourceNote: string;             // 1-line on baseline source
}

export const INDUSTRY_BENCHMARKS: Record<string, IndustryBenchmarkData> = {
  "local-services": {
    avgDomainAuthority: 145,
    avgReferringDomains: 145,
    avgBacklinks: 620,
    avgAiOverviewCitationRate: 0.08,
    avgPageCount: 24,
    avgSchemaCoverage: 0.45,
    p25DomainAuthority: 80,
    p75DomainAuthority: 220,
    sampleSize: "rough_estimate",
    avgCustomerValue: 2400,
    avgConversionRate: 0.038,
    sourceNote: "Estimate: HubSpot SMB service industry report, Ruler Analytics local service avg LTV",
  },
  "healthcare-medical": {
    avgDomainAuthority: 210,
    avgReferringDomains: 210,
    avgBacklinks: 880,
    avgAiOverviewCitationRate: 0.06,
    avgPageCount: 38,
    avgSchemaCoverage: 0.38,
    p25DomainAuthority: 90,
    p75DomainAuthority: 380,
    sampleSize: "rough_estimate",
    avgCustomerValue: 4200,
    avgConversionRate: 0.062,
    sourceNote: "Estimate: First Page Sage healthcare conversion benchmark, MGMA patient LTV baselines",
  },
  "healthcare-dental": {
    avgDomainAuthority: 180,
    avgReferringDomains: 180,
    avgBacklinks: 740,
    avgAiOverviewCitationRate: 0.07,
    avgPageCount: 28,
    avgSchemaCoverage: 0.42,
    p25DomainAuthority: 75,
    p75DomainAuthority: 310,
    sampleSize: "rough_estimate",
    avgCustomerValue: 3800,
    avgConversionRate: 0.058,
    sourceNote: "Estimate: Dental economics industry data, WordStream dental vertical conversion rates",
  },
  "b2b-saas": {
    avgDomainAuthority: 680,
    avgReferringDomains: 680,
    avgBacklinks: 4200,
    avgAiOverviewCitationRate: 0.14,
    avgPageCount: 95,
    avgSchemaCoverage: 0.52,
    p25DomainAuthority: 220,
    p75DomainAuthority: 1400,
    sampleSize: "rough_estimate",
    avgCustomerValue: 8500,
    avgConversionRate: 0.024,
    sourceNote: "Estimate: First Page Sage B2B SaaS report, OpenView SaaS benchmarks 2024",
  },
  "ecommerce": {
    avgDomainAuthority: 420,
    avgReferringDomains: 420,
    avgBacklinks: 3100,
    avgAiOverviewCitationRate: 0.12,
    avgPageCount: 280,
    avgSchemaCoverage: 0.68,
    p25DomainAuthority: 120,
    p75DomainAuthority: 850,
    sampleSize: "rough_estimate",
    avgCustomerValue: 85,
    avgConversionRate: 0.022,
    sourceNote: "Estimate: IRP Commerce ecommerce benchmarks, Shopify conversion rate data 2024",
  },
  "professional-services": {
    avgDomainAuthority: 195,
    avgReferringDomains: 195,
    avgBacklinks: 780,
    avgAiOverviewCitationRate: 0.09,
    avgPageCount: 32,
    avgSchemaCoverage: 0.40,
    p25DomainAuthority: 70,
    p75DomainAuthority: 360,
    sampleSize: "rough_estimate",
    avgCustomerValue: 5500,
    avgConversionRate: 0.032,
    sourceNote: "Estimate: HubSpot professional services benchmark, Hinge Marketing research",
  },
  "finance": {
    avgDomainAuthority: 520,
    avgReferringDomains: 520,
    avgBacklinks: 3800,
    avgAiOverviewCitationRate: 0.11,
    avgPageCount: 68,
    avgSchemaCoverage: 0.47,
    p25DomainAuthority: 180,
    p75DomainAuthority: 980,
    sampleSize: "rough_estimate",
    avgCustomerValue: 12000,
    avgConversionRate: 0.028,
    sourceNote: "Estimate: First Page Sage financial services report, BAI consumer finance data",
  },
  "legal": {
    avgDomainAuthority: 240,
    avgReferringDomains: 240,
    avgBacklinks: 1100,
    avgAiOverviewCitationRate: 0.07,
    avgPageCount: 44,
    avgSchemaCoverage: 0.36,
    p25DomainAuthority: 85,
    p75DomainAuthority: 440,
    sampleSize: "rough_estimate",
    avgCustomerValue: 7500,
    avgConversionRate: 0.041,
    sourceNote: "Estimate: Clio legal benchmarks, WordStream legal vertical CPC/conversion data",
  },
  "real-estate": {
    avgDomainAuthority: 310,
    avgReferringDomains: 310,
    avgBacklinks: 1650,
    avgAiOverviewCitationRate: 0.10,
    avgPageCount: 55,
    avgSchemaCoverage: 0.50,
    p25DomainAuthority: 100,
    p75DomainAuthority: 580,
    sampleSize: "rough_estimate",
    avgCustomerValue: 18000,
    avgConversionRate: 0.019,
    sourceNote: "Estimate: NAR real estate data, First Page Sage real estate vertical report",
  },
  "nonprofit": {
    avgDomainAuthority: 175,
    avgReferringDomains: 175,
    avgBacklinks: 820,
    avgAiOverviewCitationRate: 0.05,
    avgPageCount: 42,
    avgSchemaCoverage: 0.33,
    p25DomainAuthority: 60,
    p75DomainAuthority: 320,
    sampleSize: "rough_estimate",
    avgCustomerValue: 0,      // donation-based — handled as special case (avg donation used instead)
    avgConversionRate: 0.015,
    sourceNote: "Estimate: M+R Benchmarks nonprofit digital 2024, avg online donation ~$128",
  },
  "hospitality": {
    avgDomainAuthority: 260,
    avgReferringDomains: 260,
    avgBacklinks: 1350,
    avgAiOverviewCitationRate: 0.13,
    avgPageCount: 48,
    avgSchemaCoverage: 0.55,
    p25DomainAuthority: 90,
    p75DomainAuthority: 480,
    sampleSize: "rough_estimate",
    avgCustomerValue: 45,
    avgConversionRate: 0.048,
    sourceNote: "Estimate: Toast restaurant benchmarks, OpenTable avg ticket value data 2024",
  },
  "higher-ed": {
    avgDomainAuthority: 1850,
    avgReferringDomains: 1850,
    avgBacklinks: 18000,
    avgAiOverviewCitationRate: 0.18,
    avgPageCount: 420,
    avgSchemaCoverage: 0.44,
    p25DomainAuthority: 480,
    p75DomainAuthority: 3800,
    sampleSize: "rough_estimate",
    avgCustomerValue: 6500,
    avgConversionRate: 0.035,
    sourceNote: "Estimate: EduVentures higher ed enrollment data, NCES tuition revenue per student",
  },
  "other": {
    avgDomainAuthority: 160,
    avgReferringDomains: 160,
    avgBacklinks: 680,
    avgAiOverviewCitationRate: 0.07,
    avgPageCount: 28,
    avgSchemaCoverage: 0.38,
    p25DomainAuthority: 55,
    p75DomainAuthority: 290,
    sampleSize: "rough_estimate",
    avgCustomerValue: 1200,
    avgConversionRate: 0.030,
    sourceNote: "Estimate: Cross-industry averages from HubSpot State of Marketing 2024",
  },
};

export function getBenchmarkForIndustry(industry: string): IndustryBenchmarkData {
  return INDUSTRY_BENCHMARKS[industry] ?? INDUSTRY_BENCHMARKS["other"]!;
}
