const BASE_URL = "https://www.elevaseo.com";

interface BlogPost {
  author: string;
  authorImage: string;
  authorTwitter?: string;
  canonical: string;
  category: string;
  categorySlug: string;
  date: string;
  description: string;
  image?: string;
  imageAlt: string;
  isFamilyFriendly: boolean;
  lastmod: string;
  slug: string;
  tags: string[];
  title: string;
  wordCount: number;
}

export function buildBlogPostingJsonLd(post: BlogPost, locale: string) {
  const prefix = locale === "fr" ? "" : `/${locale}`;
  const articleUrl = `${BASE_URL}${prefix}/blog/${post.categorySlug}/${post.slug}`;

  const authorSameAs = [
    "https://www.linkedin.com/in/bastien-allain-372392389/",
  ];
  if (post.authorTwitter) {
    authorSameAs.push(`https://x.com/${post.authorTwitter}`);
  }

  return {
    "@context": "https://schema.org",
    "@type": "BlogPosting",
    headline: post.title,
    description: post.description,
    author: {
      "@type": "Person",
      name: post.author,
      image: `${BASE_URL}${post.authorImage}`,
      jobTitle:
        locale === "fr"
          ? "Fondateur & Specialiste Headless"
          : "Founder & Headless Specialist",
      url: `${BASE_URL}/about`,
      sameAs: authorSameAs,
      worksFor: {
        "@type": "Organization",
        name: "ElevaSEO",
        url: BASE_URL,
      },
    },
    datePublished: post.date,
    dateModified: post.lastmod,
    image: post.image
      ? `${BASE_URL}${post.image}`
      : `${BASE_URL}/blog/placeholder.webp`,
    publisher: {
      "@type": "Organization",
      name: "ElevaSEO",
      url: BASE_URL,
      logo: {
        "@type": "ImageObject",
        url: `${BASE_URL}/logo.webp`,
      },
    },
    mainEntityOfPage: {
      "@type": "WebPage",
      "@id": articleUrl,
    },
    wordCount: post.wordCount,
    articleSection: post.category,
    keywords: post.tags.join(", "),
    inLanguage: locale,
    isFamilyFriendly: post.isFamilyFriendly,
  };
}
