import { NextRequest, NextResponse } from 'next/server'

/**
 * Proxy for /api/recordings base endpoint
 */

const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:8000'

export async function GET(request: NextRequest) {
  const url = `${BACKEND_URL}/api/recordings`

  try {
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    })

    const data = await response.text()
    return new NextResponse(data, {
      status: response.status,
      headers: {
        'Content-Type': response.headers.get('content-type') || 'application/json',
      },
    })
  } catch (error) {
    console.error(`Failed to proxy GET ${url}:`, error)
    return NextResponse.json(
      { error: 'Backend nicht erreichbar', details: error instanceof Error ? error.message : 'Unknown error' },
      { status: 502 }
    )
  }
}
