import type { FAQContent } from "@/content/types";
import { plainText } from "@/components/rich-text";
import { reviewLinks, site } from "@/content/site";
export const businessSchema = {
  "@context": "https://schema.org",
  "@type": ["FinancialService", "LocalBusiness"],
  "@id": "https://maxcredit.sg/#business",
  name: site.name,
  url: "https://maxcredit.sg",
  image: "https://maxcredit.sg/images/Max-Credit-Logo_800px_blue.webp",
  logo: "https://maxcredit.sg/images/icon-512.png",
  telephone: site.phone,
  faxNumber: site.fax,
  contactPoint: {
    "@type": "ContactPoint",
    telephone: site.phone,
    url: "https://maxcredit.sg/contact",
    contactType: "customer service",
  },
  address: {
    "@type": "PostalAddress",
    streetAddress: "447 Clementi Avenue 3, #01-201",
    addressLocality: "Singapore",
    postalCode: "120447",
    addressCountry: "SG",
  },
  identifier: {
    "@type": "PropertyValue",
    propertyID: "MinLaw licence",
    value: site.licence,
  },
  sameAs: [reviewLinks.read],
  openingHoursSpecification: [
    {
      "@type": "OpeningHoursSpecification",
      dayOfWeek: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
      opens: "11:00",
      closes: "20:00",
    },
    {
      "@type": "OpeningHoursSpecification",
      dayOfWeek: ["Saturday"],
      opens: "11:00",
      closes: "16:00",
    },
  ],
};
export const faqSchema = (items: readonly FAQContent[]) => ({
  "@context": "https://schema.org",
  "@type": "FAQPage",
  mainEntity: items.map((item) => ({
    "@type": "Question",
    name: item.question,
    acceptedAnswer: { "@type": "Answer", text: plainText(item.answer) },
  })),
});
export const websiteSchema = {
  "@context": "https://schema.org",
  "@type": "WebSite",
  "@id": "https://maxcredit.sg/#website",
  url: "https://maxcredit.sg/",
  name: "MaxCredit",
  inLanguage: "en-SG",
  publisher: { "@id": businessSchema["@id"] },
};
export const serializeStructuredData = (value: unknown) =>
  JSON.stringify(value)
    .replaceAll("<", "\\u003c")
    .replaceAll("\u2028", "\\u2028")
    .replaceAll("\u2029", "\\u2029");
