import { serializeBigInt } from "@/app/utils";
import { resolvePropertyMeta } from "@/lib/services/epcSources";
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest, props: { params: Promise<{ propertyId: string }> }) {
  const params = await props.params;
  const propertyId = params.propertyId;

  // `detailsEpc` and the headline SAP/EPC are resolved via the cutoff: legacy
  // properties read property_details_epc / the property row; new-approach ones
  // read property_baseline_performance (the property-row headline columns aren't
  // written yet). See src/lib/services/epcSources.ts.
  const propertyMeta = await resolvePropertyMeta(propertyId);

  if (!propertyMeta) {
    return new NextResponse(null, { status: 404 });
  }

  return new NextResponse(JSON.stringify(propertyMeta, serializeBigInt));
}
