import { NextRequest, NextResponse } from "next/server"; import { getEffectiveMinStay } from "@/src/lib/beds24"; import { getApartmentBySlug, bookingConfig } from "@/src/config/apartments"; export const dynamic = "force-dynamic"; export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url); const apartmentSlug = searchParams.get("apartmentSlug"); const arrival = searchParams.get("arrival"); if (!apartmentSlug || !arrival) { return NextResponse.json( { error: "Missing required parameters: apartmentSlug, arrival" }, { status: 400 } ); } const apartment = getApartmentBySlug(apartmentSlug); if (!apartment) { return NextResponse.json( { error: "Apartment not found" }, { status: 404 } ); } const minStayNights = await getEffectiveMinStay( apartment.houseId, apartment.beds24PropertyId, apartment.beds24RoomId, arrival, bookingConfig.minStayNights ); return NextResponse.json({ apartmentSlug, arrival, minStayNights }); } catch (error) { console.error("Min-stay API error:", error); return NextResponse.json( { error: "Failed to determine minimum stay" }, { status: 500 } ); } }