import { JsonLd } from './JsonLd';
import { generateProductSchema, generateCategorizedProductSchema } from '@/lib/seo/schema/productSchema';
import { generateProductBreadcrumbs } from '@/lib/seo/schema/breadcrumbSchema';
import { Locale } from '@/lib/seo/keywords/types';

interface ProductSchemaProps {
  baseUrl: string;
  locale: Locale;
  product: {
    name: string;
    slug: string;
    description: string;
    images: string[];
    price: {
      amount: number;
      currency: string;
    };
    sku?: string;
    availability?: 'InStock' | 'OutOfStock' | 'PreOrder';
  };
  category?: 'antiAging' | 'hydration' | 'glow' | 'sensitive' | 'natural' | 'organic';
  rating?: {
    value: number;
    count: number;
  };
  includeBreadcrumbs?: boolean;
}

/**
 * Product schema component
 * Renders Product + BreadcrumbList JSON-LD schemas
 * 
 * @param baseUrl - Site base URL
 * @param locale - Current locale
 * @param product - Product data object
 * @param category - Optional category for enhanced targeting
 * @param rating - Optional aggregate rating data
 * @param includeBreadcrumbs - Whether to include breadcrumb schema (default: true)
 */
export function ProductSchema({
  baseUrl,
  locale,
  product,
  category,
  rating,
  includeBreadcrumbs = true,
}: ProductSchemaProps) {
  // Generate product schema
  const productSchema = category
    ? generateCategorizedProductSchema(baseUrl, locale, { ...product, rating }, category)
    : generateProductSchema(baseUrl, locale, { ...product, rating });

  // Generate breadcrumbs if requested
  if (includeBreadcrumbs) {
    const breadcrumbSchema = generateProductBreadcrumbs(
      baseUrl,
      locale,
      product.name,
      product.slug
    );
    return <JsonLd data={[productSchema, breadcrumbSchema]} />;
  }

  return <JsonLd data={productSchema} />;
}

export default ProductSchema;
