import { NextRequest } from 'next/server';

const HGM_URL = 'https://atlas.harita.gov.tr/webservis/ortofoto';
const HGM_KEY = 'blFTJejQ0rAxRG9gMvneL13AQXPsckFh';

export async function GET(_req: NextRequest, { params }: { params: Promise<{ z: string; x: string; y: string }> }) {
  const { z, x, y } = await params;
  const res = await fetch(`${HGM_URL}/${z}/${x}/${y}.jpg?apikey=${HGM_KEY}`, {
    headers: { 'Referer': 'https://parselsorgu.tkgm.gov.tr/', 'Origin': 'https://parselsorgu.tkgm.gov.tr', 'User-Agent': 'Mozilla/5.0' },
    next: { revalidate: 86400 },
  });
  if (!res.ok) return new Response(null, { status: res.status });
  return new Response(res.body, {
    headers: { 'Content-Type': 'image/jpeg', 'Cache-Control': 'public, max-age=86400, s-maxage=604800', 'Access-Control-Allow-Origin': '*' },
  });
}
