import { NextRequest, NextResponse } from 'next/server'
import { testWebhook } from '@/lib/discord-webhook'

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const { webhookUrl } = body

    if (!webhookUrl) {
      return NextResponse.json(
        { success: false, error: 'Webhook URL is required' },
        { status: 400 }
      )
    }

    const result = await testWebhook(webhookUrl)
    
    return NextResponse.json(result)
  } catch (error) {
    console.error('[Installer] Webhook test error:', error)
    return NextResponse.json(
      { success: false, error: 'Failed to test webhook' },
      { status: 500 }
    )
  }
}
