import { NextRequest, NextResponse } from 'next/server'
import { getOperators } from '@/lib/rumahotp'

export const dynamic = 'force-dynamic'

export async function GET(req: NextRequest) {
  try {
    const { searchParams } = new URL(req.url)
    const country = searchParams.get('country') || ''
    const providerId = parseInt(searchParams.get('provider_id') || '0')

    if (!country || !providerId) {
      return NextResponse.json({ error: 'Parameter country dan provider_id diperlukan' }, { status: 400 })
    }

    const operators = await getOperators(country, providerId)
    return NextResponse.json({ operators })
  } catch (error) {
    console.error('[OTP OPERATORS]', error)
    return NextResponse.json({ error: 'Gagal memuat daftar operator' }, { status: 500 })
  }
}
