import { businessConfig } from "@/lib/seo-config"

interface FAQItem {
  question: string
  answer: string
}

interface FAQSchemaProps {
  faqs: FAQItem[]
  pageUrl?: string
}

/**
 * FAQ Schema Component
 * Implements FAQPage schema markup for SEO and rich results
 * Helps AI/LLM understand FAQ content structure
 */
export function FAQSchema({ faqs, pageUrl }: FAQSchemaProps) {
  if (!faqs || faqs.length === 0) {
    return null
  }

  const mainEntity = faqs.map((faq) => ({
    "@type": "Question",
    name: faq.question,
    acceptedAnswer: {
      "@type": "Answer",
      text: faq.answer,
    },
  }))

  const structuredData = {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    mainEntity: mainEntity,
    ...(pageUrl && { url: pageUrl }),
    publisher: {
      "@type": "Organization",
      name: businessConfig.name,
      logo: {
        "@type": "ImageObject",
        url: `${businessConfig.website}/rmv-logo.png`,
      },
    },
  }

  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
    />
  )
}
