import { NextResponse } from "next/server";
import { getBotInfo } from "@/lib/bot-api";

export const dynamic = "force-dynamic";

/** Public subset of bot /api/info (contract §3в) for storefront UI. */
export async function GET() {
  try {
    const info = await getBotInfo();
    return NextResponse.json({
      ok: true,
      name: info.name,
      address: info.address,
      phone: info.phone,
      tg_link: info.tg_link,
      hours: info.hours,
      offhours_messages: info.offhours_messages,
      delivery: { enabled: info.delivery.enabled, cook_time_min: info.delivery.cook_time_min ?? null, order_cutoff_min: info.delivery.order_cutoff_min ?? null, updated_at: info.delivery.updated_at ?? null, error: info.delivery.error ?? null },
      pickup: info.pickup ? { enabled: info.pickup.enabled } : undefined,
      zones: info.zones.map((zone) => ({ zone: zone.zone, name: zone.name, min_order: zone.min_order, delivery_fee: zone.delivery_fee, free_from: zone.free_from })),
      server_time: info.server_time
    }, { headers: { "Cache-Control": "public, max-age=300, stale-while-revalidate=600" } });
  } catch {
    return NextResponse.json({ ok: false, error: "info_unavailable" }, { status: 502, headers: { "Cache-Control": "no-store" } });
  }
}
