import { readFileSync } from 'fs';
import { join } from 'path';
import { ImageResponse } from 'next/og';

/**
 * Loads the Inter fonts for use in Satori (Next.js OG Image generation).
 * Since we are using runtime = 'nodejs', we can read them from the filesystem.
 */
export async function getOgFonts() {
  try {
    const boldFontData = await fetch(
      new URL('../public/fonts/Inter-Bold.ttf', import.meta.url)
    ).then((res) => res.arrayBuffer());

    const regularFontData = await fetch(
      new URL('../public/fonts/Inter-Regular.ttf', import.meta.url)
    ).then((res) => res.arrayBuffer());

    return [
      {
        name: 'Inter',
        data: boldFontData,
        style: 'normal' as const,
        weight: 700 as const,
      },
      {
        name: 'Inter',
        data: regularFontData,
        style: 'normal' as const,
        weight: 400 as const,
      },
    ];
  } catch (error) {
    console.error(`[OG] Failed to load fonts:`, error);
    return [];
  }
}

/**
 * Common configuration for OG images
 */
export const OG_IMAGE_SIZE = {
  width: 1200,
  height: 630,
};
