export type WebVitalGrade = "good" | "needs_improvement" | "poor";

export interface CoreWebVital {
  metric: "LCP" | "INP" | "CLS" | "FCP" | "TTFB";
  displayName: string;
  unit: "ms" | "s" | "score";
  fieldValue: number | null;
  fieldGrade: WebVitalGrade | null;
  labValue: number | null;
  labGrade: WebVitalGrade | null;
  goodThreshold: number;
  poorThreshold: number;
  description: string;
}

export interface RenderBlockingResource {
  url: string;
  wastedMs: number;
  resourceType: "script" | "stylesheet" | "other";
}

export interface ImageOptimizationOpportunity {
  url: string;
  wastedBytes: number;
  wastedKb: number;
  issue: string;
}

export interface PerPageSpeedAnalysis {
  pageUrl: string;
  pageLabel: string;
  strategy: "mobile" | "desktop";
  overallScore: number;
  coreWebVitals: CoreWebVital[];
  renderBlockingResources: RenderBlockingResource[];
  imageOpportunities: ImageOptimizationOpportunity[];
  topOpportunities: Array<{ title: string; description: string; wastedMs?: number; wastedBytes?: number }>;
  dataFreshness: string;
}

export interface PageSpeedInsights {
  hasInsights: boolean;
  windowDate: string;
  pagesAnalyzed: number;
  overallScoreTier: "excellent" | "good" | "needs_improvement" | "poor";
  estimatedMonthlyTrafficLoss: number;
  estimatedMonthlyRevenueLoss: number;
  perPageAnalyses: PerPageSpeedAnalysis[];
  aggregateCwvGrades: Record<"LCP" | "INP" | "CLS" | "FCP" | "TTFB", WebVitalGrade | null>;
  topRenderBlockingResources: RenderBlockingResource[];
  topImageOpportunities: ImageOptimizationOpportunity[];
  patentRelevance: string;
  costMetrics: {
    pagesAnalyzed: number;
    runtimeSeconds: number;
    estimatedCostUsd: number;
  };
}
