export class ConfigLayerRegistry {
    byAgentId = new Map();
    setPeerSnapshot(agentId, peerId, snapshot) {
        let entry = this.byAgentId.get(agentId);
        if (!entry) {
            entry = { order: [], byPeerId: new Map() };
            this.byAgentId.set(agentId, entry);
        }
        if (!entry.byPeerId.has(peerId)) {
            entry.order.push(peerId);
        }
        entry.byPeerId.set(peerId, snapshot);
    }
    removePeerSnapshot(agentId, peerId) {
        const entry = this.byAgentId.get(agentId);
        if (!entry) {
            return;
        }
        entry.byPeerId.delete(peerId);
        entry.order = entry.order.filter((id) => id !== peerId);
        if (entry.order.length === 0) {
            this.byAgentId.delete(agentId);
        }
    }
    removeAgentSnapshots(agentId) {
        this.byAgentId.delete(agentId);
    }
    listPeerIds(agentId) {
        return [...(this.byAgentId.get(agentId)?.order ?? [])];
    }
    getPrimaryPeerSnapshot(agentId) {
        const entry = this.byAgentId.get(agentId);
        if (!entry) {
            return undefined;
        }
        const first = entry.order[0];
        return first ? entry.byPeerId.get(first) : undefined;
    }
    listPeerSnapshots(agentId) {
        const entry = this.byAgentId.get(agentId);
        if (!entry) {
            return [];
        }
        return entry.order
            .map((peerId) => {
            const snapshot = entry.byPeerId.get(peerId);
            return snapshot ? { peerId, snapshot } : undefined;
        })
            .filter((item) => item !== undefined);
    }
}
//# sourceMappingURL=config-layer-registry.js.map