import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/lib/auth'
import { getDnsStatus } from '@/lib/services/dns-service'

/**
 * GET /api/v1/admin/orders/[id]/dns
 * Get DNS verification status for an order
 */
export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const session = await auth()

    if (!session || session.user.userType !== 'staff') {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
    }

    const { id: orderId } = await params

    const status = await getDnsStatus(orderId)

    return NextResponse.json(status)
  } catch (error) {
    console.error('Error getting DNS status:', error)

    if (error instanceof Error && error.message === 'Order not found') {
      return NextResponse.json({ error: 'Order not found' }, { status: 404 })
    }

    return NextResponse.json(
      { error: 'Failed to get DNS status' },
      { status: 500 }
    )
  }
}
