export function buildCityRentalSeo(page, origin = "") {
  const siteOrigin = String(origin || "").replace(/\/+$/, "");
  const seo = page?.seo || page?.meta || {};
  const canonical = seo.canonical || `${siteOrigin}${page?.path || ""}`;

  return {
    title: seo.title || page?.title || "Car Rental",
    description: seo.description || page?.excerpt || "",
    ogTitle: seo.ogTitle || seo.title || page?.title || "Car Rental",
    ogDescription: seo.ogDescription || seo.description || page?.excerpt || "",
    ogImage: seo.ogImage || "",
    canonical,
    robots: "index,follow",
    hreflang: Array.isArray(seo.hreflang) ? seo.hreflang : [],
    xDefault: seo.xDefault || canonical,
  };
}

export function buildCityRentalFaqSchema(page) {
  const structuredContent = page?.structuredContent || page || {};
  const faqs = Array.isArray(structuredContent?.footer?.faq)
    ? structuredContent.footer.faq
    : Array.isArray(structuredContent?.extraBlocks?.footerFaq)
      ? structuredContent.extraBlocks.footerFaq
      : [];

  return {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    mainEntity: faqs.map((faq) => ({
      "@type": "Question",
      name: faq.q,
      acceptedAnswer: {
        "@type": "Answer",
        text: faq.a,
      },
    })),
  };
}

export function buildCityRentalAutoRentalSchema(page) {
  const structuredContent = page?.structuredContent || page || {};
  const business = structuredContent?.seoBlocks?.business || {};
  const hero = structuredContent?.hero || {};

  return {
    "@context": "https://schema.org",
    "@type": "AutoRental",
    name: business.name || page?.title || "Bent.ge",
    description: business.description || "",
    url: business.siteUrl || "",
    areaServed: {
      "@type": "City",
      name: String(hero.eyebrow || "Tbilisi")
        .split(",")[0]
        .trim(),
    },
    priceRange: business.priceRange || "$25 - $100",
  };
}
