import {
  DuplicateSchemaError,
  OpenApiPeerDepMissingError
} from "./chunk-YSLTTQLC.js";
import {
  ERROR_RESPONSE_SCHEMA_NAME,
  errorResponseSchema
} from "./chunk-SOVM2VEK.js";

// runtime/shared/openapi/registry.ts
var OpenApiRegistry = class {
  zodSchemas = /* @__PURE__ */ new Map();
  pathEntries = /* @__PURE__ */ new Map();
  peer = null;
  constructor() {
    this.zodSchemas.set(ERROR_RESPONSE_SCHEMA_NAME, errorResponseSchema);
  }
  registerSchema(name, schema) {
    if (this.zodSchemas.has(name)) {
      throw new DuplicateSchemaError(name);
    }
    this.zodSchemas.set(name, schema);
  }
  registerPath(path, method, spec) {
    let methods = this.pathEntries.get(path);
    if (!methods) {
      methods = /* @__PURE__ */ new Map();
      this.pathEntries.set(path, methods);
    }
    methods.set(method, spec);
  }
  /**
   * Emit the full OpenAPI document. Lazy-imports `@anatine/zod-openapi`
   * on first call; failure to resolve raises `OpenApiPeerDepMissingError`
   * (matches the `CubeAnalyticsBackend.onModuleInit` precedent).
   *
   * OpenAPI version is pinned to `3.0.3` — Swagger UI tooling is most
   * stable on 3.0.x (see OPENAPI-PHASE-1-PLAN §Four locked decisions).
   */
  async build(info) {
    const peer = await this.loadPeer();
    const schemas = {};
    for (const [name, zodSchema] of this.zodSchemas) {
      schemas[name] = peer.generateSchema(zodSchema, false, "3.0");
    }
    const paths = {};
    for (const [path, methods] of this.pathEntries) {
      const methodMap = {};
      for (const [method, spec] of methods) {
        methodMap[method] = spec;
      }
      paths[path] = methodMap;
    }
    return {
      openapi: "3.0.3",
      info,
      paths,
      components: { schemas }
    };
  }
  /**
   * Test helper — clears registered schemas and paths, then re-seeds the
   * core `ErrorResponseDto` entry so post-reset state matches the
   * invariant established in the constructor.
   */
  reset() {
    this.zodSchemas.clear();
    this.pathEntries.clear();
    this.peer = null;
    this.zodSchemas.set(ERROR_RESPONSE_SCHEMA_NAME, errorResponseSchema);
  }
  async loadPeer() {
    if (this.peer) return this.peer;
    try {
      const specifier = "@anatine/zod-openapi";
      const mod = await import(specifier);
      this.peer = mod;
      return mod;
    } catch {
      throw new OpenApiPeerDepMissingError();
    }
  }
};

export {
  OpenApiRegistry
};
//# sourceMappingURL=chunk-4GLNY5V6.js.map