import { sharedGet, sharedSet } from "./shared.js";
const KNOWN_APPS = "knownApps";
export function setKnownApps(fn) {
    sharedSet(KNOWN_APPS, fn);
}
export function hasKnownApps() {
    return Boolean(sharedGet(KNOWN_APPS));
}
const APP_FAMILIES = "appFamilies";
export function parseAppFamilies(raw) {
    const out = new Map();
    for (const pair of raw.split(",")) {
        const [alias, root] = pair.split("=").map((s) => s.trim());
        if (!alias || !root || alias === root)
            continue;
        out.set(alias, root);
    }
    return out;
}
export function setAppFamilies(families) {
    sharedSet(APP_FAMILIES, families);
}
export function familyRoot(appId) {
    const families = sharedGet(APP_FAMILIES);
    return families?.get(appId) ?? appId;
}
export function knownApps() {
    const lookup = sharedGet(KNOWN_APPS);
    if (!lookup) {
        throw new Error("No app registry set. Call setKnownApps() at boot. See notifications/backend/src/registry.ts");
    }
    return lookup;
}
