import { NextRequest, NextResponse } from "next/server";

const CALENDAR_URL = process.env.CALENDAR_SERVICE_URL || "http://127.0.0.1:8084";

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const res = await fetch(`${CALENDAR_URL}/reminders`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(body),
    });
    const data = await res.json();
    return NextResponse.json(data, { status: res.status });
  } catch {
    return NextResponse.json({ error: "Calendar service unavailable" }, { status: 502 });
  }
}
