const CHANNEL_ID = "qqbot";
export const qqbotOnboardingAdapter = {
    channel: CHANNEL_ID,
    getStatus: async ({ cfg }) => {
        const channelCfg = cfg.channels?.[CHANNEL_ID];
        const configured = Boolean(channelCfg?.appId && channelCfg?.clientSecret);
        return {
            channel: CHANNEL_ID,
            configured,
            statusLines: [`QQ: ${configured ? "已配置" : "需要填写凭证"}`],
            selectionHint: configured ? "recommended · configured" : "需要 QQ 开放平台应用凭证",
            quickstartScore: configured ? 1 : 10,
        };
    },
    configure: async ({ cfg, prompter }) => {
        const channelCfg = cfg.channels?.[CHANNEL_ID];
        const existingAppId = channelCfg?.appId ?? "";
        const appId = String(await prompter.text({
            message: "输入 QQ 机器人 AppID",
            initialValue: existingAppId,
            validate: (val) => (val?.trim() ? undefined : "必填"),
        })).trim();
        const existingClientSecret = channelCfg?.clientSecret ?? "";
        const clientSecret = String(await prompter.text({
            message: "输入 QQ 机器人 AppSecret（clientSecret）",
            initialValue: existingClientSecret,
            validate: (val) => (val?.trim() ? undefined : "必填"),
        })).trim();
        const next = applyQQBotConfig(cfg, { appId, clientSecret });
        return { cfg: next };
    },
    disable: (cfg) => {
        const next = { ...cfg };
        const channels = { ...next.channels };
        const existing = channels[CHANNEL_ID];
        if (existing) {
            channels[CHANNEL_ID] = { ...existing, enabled: false };
            next.channels = channels;
        }
        return next;
    },
};
function applyQQBotConfig(cfg, updates) {
    const next = { ...cfg };
    const channels = { ...next.channels };
    const existing = channels[CHANNEL_ID] ?? {};
    channels[CHANNEL_ID] = {
        ...existing,
        appId: updates.appId,
        clientSecret: updates.clientSecret,
        enabled: true,
    };
    next.channels = channels;
    return next;
}
