import { plainText } from "@/components/rich-text";
import { about } from "@/content/about";
import { loanCatalog } from "@/content/loan-catalog";
import { site } from "@/content/site";
import { loanMarkdown, loanMarkdownFooter } from "@/lib/loan-markdown";

export const dynamic = "force-static";

export function GET() {
  const body = [
    "# MaxCredit",
    "",
    "> Full text of MaxCredit's published company information, Singapore office details and loan information.",
    "",
    "The information below is generated from the website's published content; each section names its source page. Contact MaxCredit for current terms and application questions. Index: https://maxcredit.sg/llms.txt",
    "",
    "## About MaxCredit",
    "",
    "Source: https://maxcredit.sg/about",
    "",
    plainText(about.hero.description),
    "",
    ...about.sections.flatMap((section) => [
      `### ${section.title}`,
      "",
      plainText(section.description),
      "",
    ]),
    `### ${about.missionHeading.title}`,
    "",
    ...about.missions.flatMap((mission) => [
      `#### ${mission.title}`,
      "",
      mission.description,
      "",
    ]),
    "## Contact MaxCredit",
    "",
    "Source: https://maxcredit.sg/contact",
    "",
    `- Company: ${site.name}`,
    `- Moneylender licence number: ${site.licence}`,
    `- Address: ${site.address}`,
    `- Telephone: ${site.phone}`,
    `- Email: ${site.email}`,
    `- Opening hours: ${site.hours.join("; ")}`,
    "",
    "## Loan information",
    "",
    ...loanCatalog.flatMap((loan) => loanMarkdown(loan, 3)),
    ...loanMarkdownFooter,
  ].join("\n");
  return new Response(body, {
    headers: {
      "Content-Type": "text/plain; charset=utf-8",
      Link: `<https://maxcredit.sg/llms.txt>; rel="describedby"`,
      "X-Robots-Tag": "noindex, follow",
    },
  });
}
