/**
 * SEO Agents Health Check API
 * Proxies health check to LangGraph service
 */

import { NextRequest, NextResponse } from 'next/server';

const LANGGRAPH_URL = process.env.LANGGRAPH_URL || 'http://127.0.0.1:8001';

export async function GET(request: NextRequest) {
  try {
    const res = await fetch(`${LANGGRAPH_URL}/health`, {
      cache: 'no-store',
    });

    if (!res.ok) {
      return NextResponse.json(
        { status: 'offline', error: 'Service unavailable' },
        { status: 503 }
      );
    }

    const data = await res.json();
    return NextResponse.json(data);
  } catch (error) {
    return NextResponse.json(
      { status: 'offline', error: 'Cannot connect to LangGraph service' },
      { status: 503 }
    );
  }
}
