//#region src/gateway/hono/routes/config-patch/channels.ts
function applyChannelsPatch(config, body) {
	const patchChannels = body.channels;
	if (patchChannels == null || typeof patchChannels !== "object" || Array.isArray(patchChannels)) return;
	if ("telegram" in patchChannels) {
		const tgRaw = patchChannels.telegram;
		if (tgRaw === null) {
			if (config.channels) delete config.channels.telegram;
		} else if (typeof tgRaw === "object" && !Array.isArray(tgRaw)) {
			const bodyTg = tgRaw;
			if (!config.channels) config.channels = { telegram: {
				enabled: false,
				allowFrom: [],
				groupAllowFrom: [],
				debug: false,
				accounts: { default: {
					accountId: "default",
					enabled: true,
					botToken: "",
					allowFrom: [],
					dmPolicy: "pairing",
					groupPolicy: "open",
					replyToMode: "off",
					historyLimit: 50,
					textChunkLimit: 4e3,
					streamMode: "partial"
				} },
				dmPolicy: "pairing",
				groupPolicy: "open",
				replyToMode: "off",
				historyLimit: 50,
				textChunkLimit: 4e3
			} };
			if (!config.channels.telegram) config.channels.telegram = {};
			const tg = config.channels.telegram;
			if (bodyTg.enabled !== void 0) tg.enabled = bodyTg.enabled;
			if (bodyTg.allowFrom !== void 0) tg.allowFrom = bodyTg.allowFrom;
			if ("apiRoot" in bodyTg) {
				const ar = bodyTg.apiRoot;
				if (ar === null || ar === void 0 || typeof ar === "string" && !ar.trim()) delete tg.apiRoot;
				else tg.apiRoot = String(ar).trim();
			}
			if (bodyTg.debug !== void 0) tg.debug = bodyTg.debug;
			if (bodyTg.streamMode !== void 0) tg.streamMode = bodyTg.streamMode;
			if ("groupAllowFrom" in bodyTg) {
				const ga = bodyTg.groupAllowFrom;
				if (ga === null || Array.isArray(ga) && ga.length === 0) delete tg.groupAllowFrom;
				else tg.groupAllowFrom = ga;
			}
			if (bodyTg.dmPolicy !== void 0) tg.dmPolicy = bodyTg.dmPolicy;
			if (bodyTg.groupPolicy !== void 0) tg.groupPolicy = bodyTg.groupPolicy;
			if (bodyTg.replyToMode !== void 0) tg.replyToMode = bodyTg.replyToMode;
			if (bodyTg.historyLimit !== void 0) tg.historyLimit = bodyTg.historyLimit;
			if (bodyTg.textChunkLimit !== void 0) tg.textChunkLimit = bodyTg.textChunkLimit;
			if ("proxy" in bodyTg) {
				const pr = bodyTg.proxy;
				if (pr === null || pr === void 0 || typeof pr === "string" && !pr.trim()) delete tg.proxy;
				else tg.proxy = String(pr).trim();
			}
			if (bodyTg.accounts !== void 0) tg.accounts = bodyTg.accounts;
		}
	}
	if ("weixin" in patchChannels) {
		const wxRaw = patchChannels.weixin;
		if (wxRaw === null) {
			if (config.channels) delete config.channels.weixin;
		} else if (typeof wxRaw === "object" && !Array.isArray(wxRaw)) {
			const wx = wxRaw;
			if (!config.channels) config.channels = {};
			if (!config.channels.weixin) config.channels.weixin = {
				enabled: false,
				dmPolicy: "open",
				allowFrom: [],
				debug: false,
				historyLimit: 50,
				textChunkLimit: 4e3
			};
			const wxTarget = config.channels.weixin;
			if (wx.enabled !== void 0) wxTarget.enabled = wx.enabled;
			if (wx.dmPolicy !== void 0) wxTarget.dmPolicy = wx.dmPolicy;
			if (wx.allowFrom !== void 0) wxTarget.allowFrom = wx.allowFrom;
			if (wx.debug !== void 0) wxTarget.debug = wx.debug;
			if (wx.streamMode !== void 0) wxTarget.streamMode = wx.streamMode;
			if (wx.historyLimit !== void 0) wxTarget.historyLimit = wx.historyLimit;
			if (wx.textChunkLimit !== void 0) wxTarget.textChunkLimit = wx.textChunkLimit;
			if ("routeTag" in wx) {
				const rt = wx.routeTag;
				if (rt === null || rt === void 0 || rt === "") delete wxTarget.routeTag;
				else wxTarget.routeTag = rt;
			}
			if (wx.accounts !== void 0) wxTarget.accounts = wx.accounts;
		}
	}
	if ("feishu" in patchChannels) {
		const fsRaw = patchChannels.feishu;
		if (fsRaw === null) {
			if (config.channels) delete config.channels.feishu;
		} else if (typeof fsRaw === "object" && !Array.isArray(fsRaw)) {
			const fs = fsRaw;
			if (!config.channels) config.channels = {};
			if (!config.channels.feishu) config.channels.feishu = {
				enabled: false,
				appId: "",
				appSecret: "",
				domain: "feishu",
				connectionMode: "websocket",
				dmPolicy: "open",
				groupPolicy: "allowlist",
				allowFrom: [],
				groupAllowFrom: [],
				requireMention: true,
				historyLimit: 50,
				textChunkLimit: 4e3,
				accounts: {}
			};
			const fsTarget = config.channels.feishu;
			if (fs.enabled !== void 0) fsTarget.enabled = fs.enabled;
			if (fs.defaultAccount !== void 0) {
				const da = fs.defaultAccount;
				if (da === null || da === "") delete fsTarget.defaultAccount;
				else fsTarget.defaultAccount = String(da);
			}
			if (fs.appId !== void 0) fsTarget.appId = fs.appId;
			if ("appSecret" in fs) {
				const v = fs.appSecret;
				if (v === null || typeof v === "string" && !String(v).trim()) delete fsTarget.appSecret;
				else fsTarget.appSecret = v;
			}
			if (fs.domain !== void 0) fsTarget.domain = fs.domain;
			if (fs.connectionMode !== void 0) fsTarget.connectionMode = fs.connectionMode;
			if (fs.verificationToken !== void 0) {
				const v = fs.verificationToken;
				if (v === null || typeof v === "string" && !String(v).trim()) delete fsTarget.verificationToken;
				else fsTarget.verificationToken = v;
			}
			if (fs.encryptKey !== void 0) {
				const v = fs.encryptKey;
				if (v === null || typeof v === "string" && !String(v).trim()) delete fsTarget.encryptKey;
				else fsTarget.encryptKey = v;
			}
			if (fs.webhookHost !== void 0) {
				const v = fs.webhookHost;
				if (v === null || typeof v === "string" && !String(v).trim()) delete fsTarget.webhookHost;
				else fsTarget.webhookHost = v;
			}
			if (fs.webhookPort !== void 0) fsTarget.webhookPort = fs.webhookPort;
			if (fs.webhookPath !== void 0) {
				const v = fs.webhookPath;
				if (v === null || typeof v === "string" && !String(v).trim()) delete fsTarget.webhookPath;
				else fsTarget.webhookPath = v;
			}
			if (fs.dmPolicy !== void 0) fsTarget.dmPolicy = fs.dmPolicy;
			if (fs.groupPolicy !== void 0) fsTarget.groupPolicy = fs.groupPolicy;
			if (fs.allowFrom !== void 0) fsTarget.allowFrom = fs.allowFrom;
			if (fs.groupAllowFrom !== void 0) {
				const ga = fs.groupAllowFrom;
				if (ga === null || Array.isArray(ga) && ga.length === 0) delete fsTarget.groupAllowFrom;
				else fsTarget.groupAllowFrom = ga;
			}
			if (fs.requireMention !== void 0) fsTarget.requireMention = fs.requireMention;
			if (fs.historyLimit !== void 0) fsTarget.historyLimit = fs.historyLimit;
			if (fs.textChunkLimit !== void 0) fsTarget.textChunkLimit = fs.textChunkLimit;
			if (fs.renderMode !== void 0) fsTarget.renderMode = fs.renderMode;
			if (fs.streaming !== void 0) fsTarget.streaming = fs.streaming;
			if (fs.reactionNotifications !== void 0) fsTarget.reactionNotifications = fs.reactionNotifications;
			if (fs.tools !== void 0) fsTarget.tools = fs.tools;
			if (fs.actions !== void 0) fsTarget.actions = fs.actions;
			if (fs.accounts !== void 0) fsTarget.accounts = fs.accounts;
		}
	}
}
//#endregion
export { applyChannelsPatch };

//# sourceMappingURL=channels.js.map