// ── Feature flags ────────────────────────────────────────────────────────────

export interface CarFeatures {
  // Roof & Comfort
  sunroof?: boolean;
  panoramicSunroof?: boolean;
  ventilatedSeats?: boolean;
  heatedSeats?: boolean;
  // Entertainment & Connectivity
  wirelessCharger?: boolean;
  HUD?: boolean;
  touchscreenSize?: string;
  digitalCluster?: boolean;
  connectedCar?: boolean;
  appleCarPlay?: boolean;
  androidAuto?: boolean;
  // Cameras & Parking
  camera360?: boolean;
  rearCamera?: boolean;
  frontParkingSensors?: boolean;
  rearParkingSensors?: boolean;
  // Driver Assistance
  cruiseControl?: boolean;
  adaptiveCruiseControl?: boolean;
  laneDepartureWarning?: boolean;
  blindSpotMonitoring?: boolean;
  autoParking?: boolean;
  // Climate & Convenience
  climateControl?: boolean;
  rearAC?: boolean;
  ambientLighting?: boolean;
  powerTailgate?: boolean;
  keylessEntry?: boolean;
  pushButtonStart?: boolean;
}

// ── EV-specific specs ─────────────────────────────────────────────────────────

export interface EVSpecs {
  batteryCapacity?: string;
  range?: string;
  chargingTime?: string;
  fastChargingTime?: string;
  fastCharging?: boolean;
  chargingType?: string;
  chargerPortType?: string;
  runningCost?: string;
  batteryWarranty?: string;
  motorType?: string;
  motorPower?: string;
  regenerativeBraking?: boolean;
}

// ── FAQs ──────────────────────────────────────────────────────────────────────

export interface CarFAQ {
  question: string;
  answer: string;
}

export interface CarReview {
  id: string;
  carId: string;
  carSlug: string;
  author: string;
  rating: number;
  title: string;
  text: string;
  createdAt: string;
}

export interface CarReviewsResponse {
  reviews: CarReview[];
  rating: number;
  reviewCount: number;
}

// ── Car sub-types ─────────────────────────────────────────────────────────────

export interface CarColor {
  name: string;
  hex?: string;
  imageUrl?: string;
}

export interface CarOwnership {
  serviceCost?: string;
  warranty?: string;
  warrantyDetails?: string;
  maintenance?: string;           // "Low" | "Medium" | "High"
  resaleValue?: string;           // "Excellent" | "Good" | "Average"
  annualMaintenanceCost?: string;
  runningCostPerKm?: string;
  insuranceCost?: string;
  maintenanceInsights?: string;
  ownershipSummary?: string;
}

export interface CarSafety {
  safetyOverview?: string;
  crashRatingSummary?: string;
  airbagInfo?: string;
  adasFeatures?: string[];
  childSafetyNotes?: string;
  safetyRating?: number;
}

export interface CarEVContent {
  evOverview?: string;
  realWorldRange?: string;
  chargingCostEstimate?: string;
  homeFastChargingAdvice?: string;
  publicChargingNetworks?: string[];
  totalCostOfOwnership?: string;
  governmentIncentives?: string;
  evOwnershipGuide?: string;
}

export interface VehicleScores {
  performance?: number;
  comfort?: number;
  features?: number;
  safety?: number;
  mileage?: number;
  ownership?: number;
  reliability?: number;
  valueForMoney?: number;
  overall?: number;
}

export interface CarSpec {
  // Engine & Performance
  engine?: string;
  displacement?: string;
  cylinders?: number;
  maxPower?: string;
  maxTorque?: string;
  topSpeed?: string;
  acceleration?: string;
  driveType?: string;
  turbocharger?: boolean;
  steeringType?: string;

  // Fuel & Efficiency
  mileage?: string;
  fuelTankCapacity?: string;

  // Dimensions
  length?: string;
  width?: string;
  height?: string;
  wheelbase?: string;
  groundClearance?: string;
  bootSpace?: string;

  // Comfort
  seatingCapacity?: number;

  // Brakes
  frontBrakes?: string;
  rearBrakes?: string;

  // Safety
  airbags?: number;
  abs?: boolean;
  EBD?: boolean;
  ESC?: boolean;
  tractionControl?: boolean;
  ADAS?: boolean;
  ncapRating?: string;
}

export interface CarVariant {
  name: string;
  price: number;
  fuelType: string;
  transmission: string;
  features: string[];
  keyFeatures?: string[];
  mileage?: string;
  engine?: string;
}

export interface CarImage {
  url: string;
  alt: string;
  isPrimary: boolean;
  category?: string;   // "exterior" | "interior" | "color" | "360"
}

/** Phase 13 — media-library backed gallery entry */
export interface CarGalleryImage {
  mediaId:      string;
  url:          string;   // desktop URL
  thumbnailUrl: string;
  tabletUrl:    string;
  mobileUrl:    string;
  alt:          string;
  isPrimary:    boolean;
  category:     string;
  order:        number;
  uploadedAt:   string;
}

// ── Main car type ─────────────────────────────────────────────────────────────

export interface Car {
  id: string;
  name: string;
  brand: string;
  model: string;
  year?: number | null;   // null when CarWale doesn't provide year (never forced to 2024)
  price: number;
  priceMin: number;
  priceMax: number;
  onRoadPrice?: number;

  fuelType: string;
  transmission: string;
  bodyType: string;

  // Colors
  color: string[];
  colors?: CarColor[];

  images: CarImage[];
  specs: CarSpec;
  variants: CarVariant[];
  features?: CarFeatures;
  evSpecs?: EVSpecs;
  faqs?: CarFAQ[];

  // Content
  overview?: string;
  highlights?: string[];
  pros: string[];
  cons: string[];

  // Raw feature groups from CarWale featureContent.pageList
  featureGroups?: Record<string, string[]>;

  // Reviews
  rating: number;
  expertRating?: number;
  reviewCount: number;
  fuelTypes?: string[];
  availableTransmissions?: string[];
  availableBodyTypes?: string[];

  // Ownership / Safety / EV (F30-32)
  ownership?: CarOwnership;
  safety?: CarSafety;
  evContent?: CarEVContent;
  vehicleScores?: VehicleScores;
  overallScore?: number;

  // Price tracking
  previousPrice?: number;
  previousPriceMin?: number;
  previousPriceMax?: number;
  priceChangedAt?: string;
  priceChangeType?: "increase" | "decrease" | "initial";
  priceChangePct?: number;
  priceChangeAmount?: number;

  // Confidence system (F41)
  publishReady?: boolean;
  needsReview?: boolean;
  overallConfidence?: number;
  confidenceLevel?: "verified" | "high" | "medium" | "needs_review";

  brochureUrl?: string;

  // ── Phase 13 — image management ──────────────────────────────────────────
  primaryImage?:  string | null;           // hero desktop URL
  imageGallery?:  CarGalleryImage[];       // media-library backed gallery
  imageStatus?:   "uploaded" | "partial" | "pending_upload";

  // Meta
  city: string[];
  isNew: boolean;
  isUpcoming?: boolean;
  launchDate?: string;
  isFeatured: boolean;
  badge?: string;
  slug?: string;
  dataSource?: string;
  scrapeVersion?: string;
  lastUpdated?: string;
}

// ── Filter / query types ──────────────────────────────────────────────────────

export interface CarFilters {
  brand?: string[];
  fuelType?: string[];
  transmission?: string[];
  bodyType?: string[];
  priceMin?: number;
  priceMax?: number;
  seating?: number;
  hasADAS?: boolean;
  minMileage?: number;
  ncapRating?: string;
  minGroundClearance?: number;
  isEV?: boolean;
  city?: string;
  isNew?: boolean;
  isUpcoming?: boolean;
  search?: string;
  sortBy?: string;
  sortOrder?: number;
  page?: number;
  limit?: number;
}

export interface PaginatedCarsResponse {
  cars: Car[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

// ── Compare types ─────────────────────────────────────────────────────────────

export interface CompareSpec {
  label: string;
  key: string;
  values: (string | number | boolean | null)[];
}

export interface CompareResponse {
  cars: Car[];
  specs: CompareSpec[];
}

// ── Homepage / Similar Cars ───────────────────────────────────────────────────

export interface HomepageData {
  featured: Car[];
  newLaunches: Car[];
  topRated: Car[];
  popularSUVs: Car[];
  popularHatchbacks: Car[];
  popularSedans: Car[];
  electricCars: Car[];
  budgetCars: Car[];
  upcomingCars: Car[];
}

export interface SimilarCarsResponse {
  similar: Car[];
  alternatives: Car[];
  budgetBelow: Car[];
  budgetAbove: Car[];
}

export interface FilterOptions {
  brands: string[];
  fuelTypes: string[];
  transmissions: string[];
  bodyTypes: string[];
  cities: string[];
}

// ── AI types ──────────────────────────────────────────────────────────────────

export interface NLSearchResponse {
  query: string;
  parsedFilters: Record<string, unknown>;
  cars: Car[];
  total: number;
}

export interface RecommendResponse {
  preferences: string;
  cars: Car[];
}

export interface AICompareResponse {
  cars: Car[];
  summary: string;
  winner?: string | null;
}

export interface ChatMessage {
  role: "user" | "assistant";
  content: string;
}

export interface ChatResponse {
  reply: string;
}

export interface AISummaryResponse {
  car_id: string;
  name: string;
  summary: string;
}

// ── News types ────────────────────────────────────────────────────────────────

export interface NewsArticle {
  id: string;
  title: string;
  slug: string;
  summary: string;
  content: string;
  category: "Launch" | "Facelift" | "EV" | "Industry" | "Review" | "Comparison" | string;
  tags: string[];
  imageUrl?: string;
  thumbnailUrl?: string;
  author: string;
  publishedAt: string;
  relatedCarIds: string[];
  isFeatured: boolean;
  isPublished: boolean;
  views: number;
  readTime: number;
}

export interface PaginatedNewsResponse {
  articles: NewsArticle[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

// ── Lead types ────────────────────────────────────────────────────────────────
export type LeadStatus = "New" | "Contacted" | "Qualified" | "Converted" | "Rejected";

export interface Lead {
  id: string;
  carId: string;
  carName: string;
  variant?: string;
  name: string;
  mobile: string;
  email?: string;
  pinCode?: string;
  city: string;
  state?: string;
  message?: string;
  source: string;
  status: LeadStatus;
  createdAt: string;
  updatedAt: string;
}

export interface LeadStats {
  totalLeads: number;
  todayLeads: number;
  weekLeads: number;
  monthLeads: number;
  totalClicks: number;
  conversionRate: number;
  byStatus: Record<LeadStatus, number>;
}

export interface LeadAnalytics {
  byDay: Array<{ date: string; leads: number; clicks: number }>;
  byBrand: Array<{ brand: string; count: number }>;
  byModel: Array<{ model: string; count: number }>;
  topCars: Array<{ carId: string; carName: string; clicks: number; leads: number }>;
}

export interface PaginatedLeadsResponse {
  leads: Lead[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

export interface CarLeadAnalytics {
  clicks: number;
  leads: number;
  conversionRate: number;
}

// ── Blog types ────────────────────────────────────────────────────────────────

export type BlogStatus = "published" | "draft" | "archived";
export type BlogCategory = "Buying Guide" | "Comparison" | "EV Guide" | "Review" | "News" | "Upcoming" | "Maintenance" | "Tips";

export interface BlogFAQ {
  question: string;
  answer: string;
}

export interface Blog {
  id: string;
  slug: string;
  title: string;
  seoTitle: string;
  metaDescription: string;
  keywords: string[];
  content: string;        // HTML
  excerpt: string;
  author: string;
  category: BlogCategory;
  tags: string[];
  relatedCarIds: string[];
  featuredImage: string;
  status: BlogStatus;
  wordCount: number;
  readTime: number;
  views: number;
  publishedAt: string;
  updatedAt: string;
  faqSchema: BlogFAQ[];
  aiGenerated: boolean;
  aiModel?: string;
}

export interface PaginatedBlogsResponse {
  blogs: Blog[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

export interface BlogStats {
  total: number;
  published: number;
  draft: number;
  todayGenerated: number;
  totalViews: number;
  byCategory: Record<string, number>;
}

// ── Comparison types ──────────────────────────────────────────────────────────

export interface ComparisonCategory {
  name: string;
  car1Score: number;
  car2Score: number;
  winner: "car1" | "car2" | "tie";
  note: string;
}

export interface CarComparison {
  id: string;
  slug: string;
  title: string;
  seoTitle: string;
  metaDescription: string;
  car1Id: string;
  car2Id: string;
  car1Name: string;
  car2Name: string;
  content: string;    // HTML
  verdict: string;
  winner: string;
  winnerReason: string;
  categories: ComparisonCategory[];
  views: number;
  publishedAt: string;
  aiGenerated: boolean;
}

export interface PaginatedComparisonsResponse {
  comparisons: CarComparison[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

// ── Brand page types ──────────────────────────────────────────────────────────

export interface BrandFAQ {
  question: string;
  answer: string;
}

export interface BrandStats {
  totalCars: number;
  priceFrom: number;
  priceTo: number;
  bodyTypes: string[];
  fuelTypes: string[];
  hasEV: boolean;
  hasUpcoming: boolean;
}

export interface BrandCars {
  all: Car[];
  popular: Car[];
  latest: Car[];
  ev: Car[];
  upcoming: Car[];
  suv: Car[];
  sedan: Car[];
  hatchback: Car[];
  byBudget: {
    under5: Car[];
    fiveTo15: Car[];
    above15: Car[];
  };
}

export interface BrandPage {
  brand: string;
  brandSlug: string;
  seoTitle: string;
  metaDescription: string;
  keywords: string[];
  ogTitle: string;
  ogDescription: string;
  overview: string;     // HTML
  history: string;      // HTML
  faqs: BrandFAQ[];
  buyingGuide: string;  // HTML
  ownershipInfo: string; // HTML
  cars: BrandCars;
  stats: BrandStats;
  pageUpdatedAt: string;
}

export interface BrandListItem {
  brand: string;
  brandSlug: string;
  totalCars: number;
  priceFrom: number;
  priceTo: number;
  avgRating: number;
  bodyTypes: string[];
  fuelTypes: string[];
  hasPage: boolean;
  pageUpdatedAt: string;
}

// ── Best-cars / programmatic SEO types ───────────────────────────────────────

export interface BestCarsCategory {
  slug: string;
  title: string;
  h1: string;
  description: string;
  icon: string;
  carCount: number;
  hasPage: boolean;
  seoTitle: string;
  updatedAt: string;
}

export interface BestCarsPage {
  categorySlug: string;
  title: string;
  h1: string;
  description: string;
  icon: string;
  seoTitle: string;
  metaDescription: string;
  keywords: string[];
  content: string;   // HTML
  faqs: Array<{ question: string; answer: string }>;
  cars: Car[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
  pageUpdatedAt: string;
}

// ── Rival types ───────────────────────────────────────────────────────────────

export interface RivalCar {
  id: string;
  name: string;
  brand: string;
  priceMin: number;
  priceMax: number;
  fuelType: string;
  bodyType: string;
  rating: number;
  imageUrl?: string;
  slug?: string;
}

export interface CarRivals {
  direct:  RivalCar[];
  budget:  RivalCar[];
  premium: RivalCar[];
}

// ── Price history types ───────────────────────────────────────────────────────

export interface PriceHistoryEntry {
  carId: string;
  price: number;
  priceMin: number;
  priceMax: number;
  changeType: "increase" | "decrease" | "initial";
  changeAmount: number;
  changePct: number;
  recordedAt: string;
  source?: string;
}

export interface CarPriceHistory {
  carId: string;
  history: PriceHistoryEntry[];
  currentPrice: number;
  currentPriceMin: number;
  currentPriceMax: number;
  previousPrice: number | null;
  changeAmount: number;
  changePct: number;
  changeType: "increase" | "decrease" | "initial" | null;
  lowestPrice: number;
  highestPrice: number;
  firstRecordedAt?: string;
  latestRecordedAt?: string;
  totalChanges?: number;
}

// ── Moderation types (F42) ────────────────────────────────────────────────────

export interface ModerationIssue {
  field: string;
  value: string;
  issue: string;
}

export interface ModerationResult {
  passed: boolean;
  rejected: boolean;
  score: number;
  errors: ModerationIssue[];
  warnings: ModerationIssue[];
  errorCount: number;
  warningCount: number;
  checkedAt: string;
}

export interface ModerationCar {
  id: string;
  name: string;
  brand: string;
  model?: string;
  slug?: string;
  moderation: ModerationResult;
}

export interface ModerationStats {
  total: number;
  passed: number;
  rejected: number;
  withWarnings: number;
  unchecked: number;
  whitelisted: number;
}

// ── F44: Car Wizard types ─────────────────────────────────────────────────────

export interface WizardInput {
  budgetMin:   number;
  budgetMax:   number;
  fuelTypes:   string[];
  bodyTypes:   string[];
  familySize:  number;
}

export interface WizardCar {
  id: string;
  name: string;
  brand: string;
  model?: string;
  priceMin: number;
  priceMax: number;
  fuelType: string;
  bodyType: string;
  transmission?: string;
  imageUrl?: string;
  primaryImage?: string | null;
  imageGallery?: CarGalleryImage[];
  slug?: string;
  rating?: number;
  reviewCount?: number;
  specs?: {
    mileage?: string;
    engine?: string;
    seatingCapacity?: number;
    airbags?: number;
    groundClearance?: string;
    bootSpace?: string;
  };
}

export interface WizardMatchResult {
  car:    WizardCar;
  reason: string;
  pros:   string[];
  cons:   string[];
}

export interface WizardAlternative extends WizardMatchResult {
  reason: string;
}

export interface WizardResult {
  bestMatch:    WizardMatchResult | null;
  alternatives: WizardAlternative[];
  totalMatches: number;
  aiPowered:    boolean;
}

// ── F43: Dealer / City Pricing / City Page types ─────────────────────────────

export interface Dealer {
  id: string;
  name: string;
  brand: string;
  city: string;
  state?: string;
  address?: string;
  phone?: string;
  email?: string;
  website?: string;
  rating?: number;
  reviewCount?: number;
  location?: { lat: number; lng: number };
  services?: string[];
  verified?: boolean;
  createdAt?: string;
  updatedAt?: string;
}

export interface CityPriceBreakdown {
  id?: string;
  carId: string;
  city: string;
  state?: string;
  exShowroom: number;
  rto: number;
  insurance: number;
  tcs?: number;
  fastag?: number;
  handling?: number;
  onRoadPrice: number;
  isEstimate?: boolean;
  updatedAt?: string;
}

export interface CarOffer {
  id: string;
  carId: string;
  title: string;
  type: "cash" | "exchange" | "bank" | "corporate" | "loyalty" | "festive" | "other";
  amount: number;
  description?: string;
  city?: string;
  bankName?: string;
  validTill?: string;
  validFrom?: string;
  terms?: string;
  active?: boolean;
}

export interface CarDiscounts {
  totalDiscount: number;
  offerCount: number;
  byType: Record<string, number>;
  offers: CarOffer[];
}

export interface WaitingPeriod {
  id?: string;
  carId: string;
  city?: string;
  waitingWeeks?: { min: number; max: number } | null;
  message?: string;
  updatedAt?: string;
}

export interface CityPageSummary {
  city: string;
  state?: string;
  slug: string;
  dealerCount: number;
  offerCount?: number;
  waitingPeriodCount?: number;
  updatedAt?: string;
  seoTitle?: string;
  seoDescription?: string;
}

export interface CityPopularCar {
  id: string;
  name: string;
  brand: string;
  priceMin: number;
  priceMax?: number;
  imageUrl?: string;
  slug?: string;
  rating?: number;
  bodyType?: string;
  fuelType?: string;
}

export interface CityPage extends CityPageSummary {
  intro?: string;
  popularCars: CityPopularCar[];
  sampleDealers: Dealer[];
  topOffers: CarOffer[];
}

// ── F48: Notifications & Watchlist types ─────────────────────────────────────

export type NotificationType =
  | "price_drop"
  | "new_variant"
  | "facelift"
  | "recall"
  | "safety_update";

export interface UserNotification {
  id:        string;
  sessionId: string;
  carId:     string;
  carName:   string;
  brand:     string;
  imageUrl?: string | null;
  carSlug:   string;
  type:      NotificationType;
  title:     string;
  message:   string;
  data?: {
    oldPrice?:       number;
    newPrice?:       number;
    priceDrop?:      number;
    priceDropPct?:   number;
    variantName?:    string;
    oldVariantCount?: number;
    newVariantCount?: number;
    recallDetails?:  string;
    field?:          string;
    from?:           string | number;
    to?:             string | number;
  };
  read:      boolean;
  createdAt: string;
}

export interface WatchedCar {
  id?:       string;
  sessionId: string;
  carId:     string;
  carName:   string;
  brand:     string;
  imageUrl?: string | null;
  carSlug:   string;
  types:     NotificationType[];
  updatedAt: string;
}

// ── F47: Weekly Analytics / Reports types ────────────────────────────────────

export interface ReportCar {
  carId:        string;
  name:         string;
  brand:        string;
  bodyType?:    string;
  fuelType?:    string;
  priceMin?:    number;
  slug?:        string;
  rating?:      number;
  imageUrl?:    string | null;
  viewCount:    number;
  compareCount: number;
}

export interface ReportBrand {
  brand:        string;
  viewCount:    number;
  compareCount: number;
  topCar?:      Partial<ReportCar>;
}

export interface ReportEV extends ReportCar {
  prevViewCount: number;
  growthPct:     number;
}

export interface WeeklyReport {
  id?:               string;
  week:              string;      // "2026-W23"
  startDate:         string;      // ISO
  endDate:           string;      // ISO
  generatedAt:       string;      // ISO
  popularCars:       ReportCar[];
  popularBrands:     ReportBrand[];
  fastestGrowingEvs: ReportEV[];
  mostViewedCars:    ReportCar[];
  mostComparedCars:  ReportCar[];
  totalViews:        number;
  totalCompares:     number;
  uniqueCarsViewed:  number;
  dataSource?:       "events" | "fallback";
}

export interface WeeklyReportSummary {
  id?:              string;
  week:             string;
  startDate:        string;
  endDate:          string;
  generatedAt:      string;
  totalViews:       number;
  totalCompares:    number;
  uniqueCarsViewed: number;
}

// ── F46: Ownership Cost types ─────────────────────────────────────────────────

export interface OwnershipInsuranceDetail {
  idv:         number;   // Insured Declared Value
  odGross:     number;   // Own Damage premium (before NCB)
  ncbDiscount: number;   // No-Claim Bonus savings
  odNet:       number;   // Own Damage after NCB
  tp:          number;   // Third-Party premium (fixed)
  ncbPct:      number;   // 0 | 20 | 25 | 35 | 45
}

export interface OwnershipYear {
  year:              number;
  fuelCost:          number;
  insurance:         number;
  serviceCost:       number;
  maintenance:       number;
  depreciation:      number;
  total:             number;
  cumulative:        number;
  insuranceDetail:   OwnershipInsuranceDetail;
}

export interface OwnershipCostSummary {
  total5yr:   number;
  avgAnnual:  number;
  costPerKm:  number;
  byCategory: {
    fuelCost:     number;
    insurance:    number;
    serviceCost:  number;
    maintenance:  number;
    depreciation: number;
  };
}

export interface OwnershipCostResult {
  carId:       string;
  carName:     string;
  fuelType:    string;
  mileage:     number;   // km/l or km/kWh
  kmPerYear:   number;
  exShowroom:  number;
  onRoadPrice: number;
  years:       OwnershipYear[];
  summary:     OwnershipCostSummary;
}

// ── F49: Data Quality types ───────────────────────────────────────────────────

export interface QualityBucket {
  count:  number;
  target: number;
  ok:     boolean;
}

export interface CarQualityReport {
  carId:  string;
  name:   string;
  brand:  string;
  year:   number | null;
  score:  number;          // 0–100
  grade:  "A" | "B" | "C" | "F";
  images:   QualityBucket;
  specs:    QualityBucket;
  variants: QualityBucket;
  gaps:              string[];   // ["images","specs","variants"]
  missingSpecFields: string[];
}

export interface QualityAuditSummary {
  total:     number;
  deficient: number;
  healthy:   number;
  avgScore:  number;
  gradeDistribution: { A: number; B: number; C: number; F: number };
}

export interface QualityStats {
  total:                number;
  imgDeficient:         number;
  varDeficient:         number;
  avgImages:            number;
  avgVariants:          number;
  enrichmentRuns:       number;
  enrichmentSuccessful: number;
  targets:              { images: number; variants: number };
}

export interface EnrichmentAction {
  step:          string;
  count?:        number;
  fieldsAdded?:  string[];
  added?:        number | string[];
  corrections?:  number;
  issues?:       string[];
}

export interface EnrichmentLog {
  carId:       string;
  carName:     string;
  startedAt:   string;
  completedAt: string;
  success:     boolean;
  error?:      string;
  scoreGain:   number;
  gapsFixed:   number;
  actions:     EnrichmentAction[];
  before: { score: number; grade: string; imageCount: number; specCount: number; variantCount: number; gaps: string[] };
  after?:  { score: number; grade: string; imageCount: number; specCount: number; variantCount: number; gaps: string[] };
}

// ── SEO health types ──────────────────────────────────────────────────────────

export interface SeoHealthReport {
  id: string;
  checkedAt: string;
  cars: {
    checked: number;
    missingMetadata: number;
    missingImages: number;
    missingPros: number;
    missingFaqs: number;
    thinContent: number;
    fixed: number;
  };
  blogs: {
    checked: number;
    thinContent: number;
    missingMeta: number;
  };
  comparisons: {
    checked: number;
    missingMeta: number;
  };
  issues: Array<{
    type: "car" | "blog" | "comparison";
    id: string;
    name?: string;
    title?: string;
    issues: string[];
  }>;
}
