import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
import { z } from "zod";
//#region extensions/telegram/src/config-schema.ts
/** Migrate legacy top-level `botToken` into `accounts.default`; implicit enable when `accounts.default.botToken` is set. */
function preprocessTelegramConfigInput(raw) {
	if (raw === null || raw === void 0) return raw;
	if (typeof raw !== "object" || Array.isArray(raw)) return raw;
	const o = { ...raw };
	const legacyToken = typeof o.botToken === "string" ? o.botToken.trim() : "";
	if (legacyToken) {
		const acc = { ...o.accounts && typeof o.accounts === "object" && !Array.isArray(o.accounts) ? o.accounts : {} };
		const rawDef = acc.default;
		const def = rawDef && typeof rawDef === "object" && !Array.isArray(rawDef) ? { ...rawDef } : {};
		if (!(typeof def.botToken === "string" ? def.botToken.trim() : "")) acc.default = {
			...def,
			accountId: "default",
			botToken: legacyToken
		};
		o.accounts = acc;
	}
	delete o.botToken;
	const defaultAcc = o.accounts?.default;
	const token = defaultAcc && typeof defaultAcc === "object" && typeof defaultAcc.botToken === "string" ? defaultAcc.botToken : "";
	if (o.enabled === void 0 && token.trim().length > 0) o.enabled = true;
	return o;
}
var TelegramTopicConfigSchema, TelegramGroupConfigSchema, TelegramAccountConfigSchema, TelegramConfigSchemaInner, TelegramConfigSchema;
var init_config_schema = __esmMin((() => {
	TelegramTopicConfigSchema = z.object({
		topicId: z.string(),
		requireMention: z.boolean().optional(),
		enabled: z.boolean().optional(),
		allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
		systemPrompt: z.string().optional()
	});
	TelegramGroupConfigSchema = z.object({
		groupId: z.string(),
		requireMention: z.boolean().optional(),
		enabled: z.boolean().optional(),
		allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
		systemPrompt: z.string().optional(),
		topics: z.record(z.string(), TelegramTopicConfigSchema).optional()
	});
	TelegramAccountConfigSchema = z.object({
		accountId: z.string(),
		name: z.string().optional(),
		enabled: z.boolean().default(true),
		botToken: z.string().default(""),
		tokenFile: z.string().optional(),
		allowFrom: z.array(z.union([z.string(), z.number()])).default([]),
		groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
		dmPolicy: z.enum([
			"pairing",
			"allowlist",
			"open",
			"disabled"
		]).default("pairing"),
		groupPolicy: z.enum([
			"open",
			"disabled",
			"allowlist"
		]).default("open"),
		replyToMode: z.enum([
			"off",
			"first",
			"all"
		]).default("off"),
		groups: z.record(z.string(), TelegramGroupConfigSchema).optional(),
		historyLimit: z.number().default(50),
		textChunkLimit: z.number().default(4e3),
		streamMode: z.enum([
			"off",
			"partial",
			"block"
		]).default("partial"),
		proxy: z.string().optional(),
		apiRoot: z.string().optional()
	});
	TelegramConfigSchemaInner = z.object({
		enabled: z.boolean().default(false),
		allowFrom: z.array(z.union([z.string(), z.number()])).default([]),
		groupAllowFrom: z.array(z.union([z.string(), z.number()])).default([]),
		apiRoot: z.string().optional(),
		debug: z.boolean().default(false),
		accounts: z.record(z.string(), TelegramAccountConfigSchema).optional(),
		dmPolicy: z.enum([
			"pairing",
			"allowlist",
			"open",
			"disabled"
		]).default("pairing"),
		groupPolicy: z.enum([
			"open",
			"disabled",
			"allowlist"
		]).default("open"),
		replyToMode: z.enum([
			"off",
			"first",
			"all"
		]).default("off"),
		streamMode: z.enum([
			"off",
			"partial",
			"block"
		]).optional(),
		historyLimit: z.number().default(50),
		textChunkLimit: z.number().default(4e3),
		proxy: z.string().optional()
	});
	TelegramConfigSchema = z.preprocess(preprocessTelegramConfigInput, TelegramConfigSchemaInner);
}));
//#endregion
init_config_schema();
export { TelegramAccountConfigSchema, TelegramConfigSchema, TelegramGroupConfigSchema, TelegramTopicConfigSchema, init_config_schema };

//# sourceMappingURL=config-schema.js.map