import { NextRequest, NextResponse } from 'next/server';
import { fetchJoDetail } from '@/app/api/jo';

export async function GET(request: NextRequest) {
  const { searchParams } = new URL(request.url);
  const id = searchParams.get('id');

  if (!id) {
    return NextResponse.json({ error: 'ID is required' }, { status: 400 });
  }

  try {
    const joDetail = await fetchJoDetail(parseInt(id));
    return NextResponse.json(joDetail);
  } catch (error) {
    console.error('Error fetching JO detail:', error);
    return NextResponse.json({ error: 'Failed to fetch JO detail' }, { status: 500 });
  }
}