/**
 * Root OG Image Route
 *
 * Serves the default AMSOIL branded OG image for the main domain.
 * Dealer-specific OG images are served via /sites/[subdomain]/og routes.
 *
 * Usage: https://myamsoil.com/og
 */

import { NextResponse } from 'next/server';
import * as fs from 'fs/promises';
import * as path from 'path';

export async function GET() {
  // Serve a generic AMSOIL branded image for main domain
  const imagePath = path.join(process.cwd(), 'public/images/og-default.png');

  try {
    const imageBuffer = await fs.readFile(imagePath);
    return new NextResponse(imageBuffer, {
      headers: {
        'Content-Type': 'image/png',
        'Cache-Control': 'public, max-age=86400', // 24 hours
        // Extensionless image URL: without this, search engines index the raw
        // binary as a "page". Social scrapers ignore noindex, so link previews
        // are unaffected. robots.txt must NOT block /og or this is never seen.
        'X-Robots-Tag': 'noindex',
      },
    });
  } catch {
    return new NextResponse('Image not found', {
      status: 404,
      headers: { 'Content-Type': 'text/plain' },
    });
  }
}
