import { NextResponse } from 'next/server'
import { getAnacZones, anacZonesToGeoJSON } from '@/lib/anac'

export const revalidate = 3600

export async function GET() {
  try {
    const zones = await getAnacZones()
    const geojson = anacZonesToGeoJSON(zones)
    return NextResponse.json(geojson, {
      headers: { 'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200' },
    })
  } catch (err) {
    console.error('ANAC zones fetch error:', err)
    return NextResponse.json({ error: 'Failed to fetch ANAC zones' }, { status: 502 })
  }
}
