import { CHANNEL_CAPABILITIES } from "./channel-capabilities.js";
function adapterWarning(config, label) {
    return config.adapterWarnings?.find((warning) => warning.startsWith(`${label} disabled:`));
}
export class TelegramChannelAdapter {
    id = "telegram";
    label = "Telegram";
    capabilities = new Set(CHANNEL_CAPABILITIES.telegram);
    describe(config) {
        if (config) {
            const warning = adapterWarning(config, "Telegram");
            return {
                id: this.id,
                label: this.label,
                capabilities: [...this.capabilities],
                status: "available",
                enabled: config.telegramEnabled,
                notes: config.telegramEnabled
                    ? `Telegram bot runtime is enabled (${config.telegramTransport}).`
                    : (warning ?? "Telegram bot runtime is disabled."),
            };
        }
        const requested = process.env.TELEGRAM_ENABLED !== "false";
        const enabled = requested && Boolean(process.env.TELEGRAM_BOT_TOKEN);
        return {
            id: this.id,
            label: this.label,
            capabilities: [...this.capabilities],
            status: "available",
            enabled,
            notes: enabled
                ? "Telegram bot runtime is enabled."
                : requested
                    ? "Telegram bot runtime is disabled because TELEGRAM_BOT_TOKEN is missing."
                    : "Telegram bot runtime is disabled.",
        };
    }
}
export class DiscordChannelAdapter {
    id = "discord";
    label = "Discord";
    capabilities = new Set(CHANNEL_CAPABILITIES.discord);
    describe(config) {
        if (config) {
            const warning = adapterWarning(config, "Discord");
            return {
                id: this.id,
                label: this.label,
                capabilities: [...this.capabilities],
                status: "available",
                enabled: config.discordEnabled,
                notes: config.discordEnabled
                    ? "Discord bot runtime is enabled."
                    : (warning ?? "Enable with DISCORD_ENABLED=true and DISCORD_BOT_TOKEN."),
            };
        }
        const requested = process.env.DISCORD_ENABLED === "true";
        const enabled = requested && Boolean(process.env.DISCORD_BOT_TOKEN);
        return {
            id: this.id,
            label: this.label,
            capabilities: [...this.capabilities],
            status: "available",
            enabled,
            notes: enabled
                ? "Discord bot runtime is enabled."
                : requested
                    ? "Discord bot runtime is disabled because DISCORD_BOT_TOKEN is missing."
                    : "Enable with DISCORD_ENABLED=true and DISCORD_BOT_TOKEN.",
        };
    }
}
export class SlackChannelAdapter {
    id = "slack";
    label = "Slack";
    capabilities = new Set(CHANNEL_CAPABILITIES.slack);
    describe(config) {
        if (config) {
            const warning = adapterWarning(config, "Slack");
            return {
                id: this.id,
                label: this.label,
                capabilities: [...this.capabilities],
                status: "available",
                enabled: config.slackEnabled,
                notes: config.slackEnabled
                    ? "Slack bot runtime is enabled."
                    : (warning ?? "Enable with SLACK_ENABLED=true, SLACK_BOT_TOKEN, and SLACK_APP_TOKEN."),
            };
        }
        const requested = process.env.SLACK_ENABLED === "true";
        const enabled = requested && Boolean(process.env.SLACK_BOT_TOKEN) && Boolean(process.env.SLACK_APP_TOKEN);
        return {
            id: this.id,
            label: this.label,
            capabilities: [...this.capabilities],
            status: "available",
            enabled,
            notes: enabled
                ? "Slack bot runtime is enabled."
                : requested
                    ? "Slack bot runtime is disabled because SLACK_BOT_TOKEN or SLACK_APP_TOKEN is missing."
                    : "Enable with SLACK_ENABLED=true, SLACK_BOT_TOKEN, and SLACK_APP_TOKEN.",
        };
    }
}
export class MatrixChannelAdapter {
    id = "matrix";
    label = "Matrix";
    capabilities = new Set(CHANNEL_CAPABILITIES.matrix);
    describe(config) {
        if (config) {
            const warning = adapterWarning(config, "Matrix");
            return {
                id: this.id,
                label: this.label,
                capabilities: [...this.capabilities],
                status: "available",
                enabled: config.matrixEnabled,
                notes: config.matrixEnabled
                    ? `Matrix bot runtime is enabled (${config.matrixHomeserverUrl ?? "homeserver"}).`
                    : (warning ?? "Enable with MATRIX_ENABLED=true, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, and MATRIX_USER_ID."),
            };
        }
        const requested = process.env.MATRIX_ENABLED === "true";
        const enabled = requested && Boolean(process.env.MATRIX_HOMESERVER_URL) && Boolean(process.env.MATRIX_ACCESS_TOKEN) && Boolean(process.env.MATRIX_USER_ID);
        return {
            id: this.id,
            label: this.label,
            capabilities: [...this.capabilities],
            status: "available",
            enabled,
            notes: enabled
                ? "Matrix bot runtime is enabled."
                : requested
                    ? "Matrix bot runtime is disabled because MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, or MATRIX_USER_ID is missing."
                    : "Enable with MATRIX_ENABLED=true, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, and MATRIX_USER_ID.",
        };
    }
}
export function listChannelDescriptors(config) {
    return [
        new TelegramChannelAdapter().describe(config),
        new DiscordChannelAdapter().describe(config),
        new SlackChannelAdapter().describe(config),
        new MatrixChannelAdapter().describe(config),
    ];
}
