import { NextRequest, NextResponse } from 'next/server'
import { CONTROLS_LIBRARY } from '@/lib/sdk/vendor-compliance'

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const domain = searchParams.get('domain')

    let controls = [...CONTROLS_LIBRARY]

    // Filter by domain if provided
    if (domain) {
      controls = controls.filter((c) => c.domain === domain)
    }

    return NextResponse.json({
      success: true,
      data: controls,
      timestamp: new Date().toISOString(),
    })
  } catch (error) {
    console.error('Error fetching controls:', error)
    return NextResponse.json(
      { success: false, error: 'Failed to fetch controls' },
      { status: 500 }
    )
  }
}
