import { NextResponse } from "next/server";
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { shippingCarrierUpstreamErrorResponse } from "../../lib/upstream-error-response.js";
import { searchDropOffPointsQuerySchema } from "../../data/validators.js";
import { shippingCarriersTag } from "../openapi.js";
const metadata = {
  path: "/shipping-carriers/points",
  GET: { requireAuth: true, requireFeatures: ["shipping_carriers.view"] }
};
async function GET(req) {
  const auth = await getAuthFromRequest(req);
  if (!auth?.tenantId || !auth.orgId) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }
  const url = new URL(req.url);
  const parsed = searchDropOffPointsQuerySchema.safeParse({
    providerKey: url.searchParams.get("providerKey"),
    query: url.searchParams.get("query") ?? void 0,
    type: url.searchParams.get("type") ?? void 0,
    postCode: url.searchParams.get("postCode") ?? void 0
  });
  if (!parsed.success) {
    return NextResponse.json({ error: "Invalid query", details: parsed.error.flatten() }, { status: 422 });
  }
  const container = await createRequestContainer();
  const service = container.resolve("shippingCarrierService");
  try {
    const points = await service.searchDropOffPoints({
      ...parsed.data,
      organizationId: auth.orgId,
      tenantId: auth.tenantId
    });
    return NextResponse.json({ points });
  } catch (error) {
    return shippingCarrierUpstreamErrorResponse("points.search", error);
  }
}
const openApi = {
  tags: [shippingCarriersTag],
  summary: "Search drop-off points",
  methods: {
    GET: {
      summary: "Search carrier drop-off points (lockers, POP points)",
      tags: [shippingCarriersTag],
      responses: [
        { status: 200, description: "Points returned" },
        { status: 422, description: "Validation failed" },
        { status: 502, description: "Provider upstream error or unsupported" }
      ]
    }
  }
};
export {
  GET,
  metadata,
  openApi
};
//# sourceMappingURL=route.js.map
