/**
 * Config key registry access (Phase 77 / REF-008).
 * Validation logic stays in `../../config-metadata.ts`; this module holds the JSON-backed registry + lookups.
 */
import registryJson from "../../config-registry.json" with { type: "json" };
/** Canonical in-memory registry (read-only surface for validators). */
export const configMetadataRegistry = registryJson;
export function getConfigKeyMetadata(key) {
    return configMetadataRegistry[key];
}
export function listConfigMetadata(options) {
    const exposure = options?.exposure ?? "public";
    const order = ["public", "maintainer", "internal"];
    const maxIdx = exposure === "all" ? 2 : order.indexOf(exposure);
    const allowed = maxIdx < 0 ? new Set(["public"]) : new Set(order.slice(0, maxIdx + 1));
    return Object.values(configMetadataRegistry)
        .filter((m) => allowed.has(m.exposure))
        .sort((a, b) => a.key.localeCompare(b.key));
}
export function assertWritableKey(key) {
    const meta = configMetadataRegistry[key];
    if (!meta) {
        const err = new Error(`config-unknown-key: '${key}' is not a registered config key`);
        err.code = "config-unknown-key";
        throw err;
    }
    if (meta.exposure === "internal") {
        const err = new Error(`config-internal-key: '${key}' is internal and not user-writable`);
        err.code = "config-internal-key";
        throw err;
    }
    return meta;
}
