import type { Metadata } from "next";
import { APP_NAME, SITE_URL } from "@/utils/constants";
import { generatePageContent } from "./content";
import type { SeoPageContext } from "./types";

export function buildSeoMetadata(ctx: SeoPageContext): Metadata {
  const content = generatePageContent(ctx);
  const canonical = `${SITE_URL}${content.canonicalPath}`;

  return {
    title: content.title,
    description: content.metaDescription,
    keywords: content.keywords,
    alternates: { canonical },
    openGraph: {
      type: "website",
      locale: "pt_BR",
      url: canonical,
      siteName: APP_NAME,
      title: `${content.title} | ${APP_NAME}`,
      description: content.metaDescription,
    },
    twitter: {
      card: "summary_large_image",
      title: content.title,
      description: content.metaDescription,
    },
    robots: {
      index: true,
      follow: true,
      googleBot: {
        index: true,
        follow: true,
        "max-image-preview": "large",
        "max-snippet": -1,
      },
    },
  };
}

export function buildBlogMetadata(post: {
  title: string;
  excerpt: string;
  slug: string;
  keywords: string[];
}): Metadata {
  const canonical = `${SITE_URL}/blog/${post.slug}`;
  return {
    title: post.title,
    description: post.excerpt,
    keywords: post.keywords,
    alternates: { canonical },
    openGraph: {
      type: "article",
      locale: "pt_BR",
      url: canonical,
      title: post.title,
      description: post.excerpt,
    },
    robots: { index: true, follow: true },
  };
}
