import { listAgentAdapterDescriptors } from "./agent-adapter.js";
import { agentFeatureStates } from "./agent-feature-matrix.js";
import { listChannelDescriptors, } from "../../channels/shared/channel-adapter.js";
import { CHANNEL_FEATURES, channelActionStates, channelFeatureStates, } from "../../channels/shared/channel-capabilities.js";
import { channelCatalogCommandNames, channelCommandCoverage, } from "../../channels/shared/channel-command-core.js";
export { CHANNEL_FEATURES, channelFeatureStates };
export function buildAdapterConformanceMatrix(input = {}) {
    const agents = input.agents ?? listAgentAdapterDescriptors();
    const channels = input.channels ?? listChannelDescriptors();
    return {
        generatedAt: new Date().toISOString(),
        agents: agents.map((adapter) => {
            const features = agentFeatureStates(adapter.capabilities);
            return {
                id: adapter.id,
                label: adapter.label,
                status: adapter.status,
                features,
                supported: features.filter((feature) => feature.supported).map((feature) => feature.key),
                unsupported: features.filter((feature) => !feature.supported).map((feature) => feature.key),
                notes: adapter.notes,
            };
        }),
        channels: channels.map((adapter) => {
            const features = channelFeatureStates(adapter.capabilities);
            const actions = channelActionStates(adapter);
            const commands = commandNamesForChannel(adapter.id);
            const commandCoverage = commandCoverageForChannel(adapter.id, commands);
            return {
                id: adapter.id,
                label: adapter.label,
                status: adapter.status,
                enabled: adapter.enabled,
                features,
                supported: features.filter((feature) => feature.supported).map((feature) => feature.key),
                unsupported: features.filter((feature) => !feature.supported).map((feature) => feature.key),
                actions,
                actionSupported: actions.filter((action) => action.supported).map((action) => action.key),
                actionUnsupported: actions.filter((action) => !action.supported).map((action) => action.key),
                commands,
                commandCoverage,
                notes: adapter.notes,
            };
        }),
    };
}
function commandNamesForChannel(id) {
    if (id === "telegram" || id === "discord" || id === "slack" || id === "matrix") {
        return channelCatalogCommandNames(id);
    }
    return [];
}
function commandCoverageForChannel(id, implemented) {
    if (id === "telegram" || id === "discord" || id === "slack" || id === "matrix") {
        return channelCommandCoverage({
            transport: id,
            implemented,
        });
    }
    return { advertised: [], implemented: [], missing: [], extra: [] };
}
