import { NextResponse } from "next/server";
import { z } from "zod";
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { Organization } from "@open-mercato/core/modules/directory/data/entities";
const metadata = {
  path: "/directory/organizations/lookup",
  GET: {
    requireAuth: false
  }
};
const orgLookupQuerySchema = z.object({
  slug: z.string().min(1).max(150)
});
async function GET(req) {
  const url = new URL(req.url);
  const slug = url.searchParams.get("slug") || "";
  const parsed = orgLookupQuerySchema.safeParse({ slug });
  if (!parsed.success) {
    return NextResponse.json({ ok: false, error: "Invalid slug." }, { status: 400 });
  }
  const container = await createRequestContainer();
  const em = container.resolve("em");
  const organization = await em.findOne(
    Organization,
    { slug: parsed.data.slug, deletedAt: null }
  );
  if (!organization) {
    return NextResponse.json({ ok: false, error: "Organization not found." }, { status: 404 });
  }
  return NextResponse.json({
    ok: true,
    organization: {
      id: String(organization.id),
      name: organization.name,
      slug: organization.slug
    }
  });
}
const lookupTag = "Directory";
const orgLookupSuccessSchema = z.object({
  ok: z.literal(true),
  organization: z.object({
    id: z.string().uuid(),
    name: z.string(),
    slug: z.string()
  })
});
const orgLookupErrorSchema = z.object({
  ok: z.literal(false),
  error: z.string()
});
const orgLookupDoc = {
  summary: "Public organization lookup by slug",
  description: "Resolves organization metadata for portal flows. No authentication required.",
  tags: [lookupTag],
  query: orgLookupQuerySchema,
  responses: [
    { status: 200, description: "Organization resolved.", schema: orgLookupSuccessSchema }
  ],
  errors: [
    { status: 400, description: "Invalid slug", schema: orgLookupErrorSchema },
    { status: 404, description: "Organization not found", schema: orgLookupErrorSchema }
  ]
};
const openApi = {
  tag: lookupTag,
  summary: "Public organization lookup by slug",
  methods: {
    GET: orgLookupDoc
  }
};
var lookup_default = GET;
export {
  GET,
  lookup_default as default,
  metadata,
  openApi
};
//# sourceMappingURL=lookup.js.map
