import { createTimeoutAbortSignal } from "../timeout-abort.js";
//#region extensions/telegram/src/adapters/status-adapter.ts
function createTelegramStatusAdapter(options) {
	const { accountManager } = options;
	return {
		defaultRuntime: {
			accountId: "default",
			channelId: "telegram",
			enabled: true,
			configured: false
		},
		buildChannelSummary: async ({ account }) => {
			const status = accountManager.getStatus(account.accountId);
			return {
				accountId: account.accountId,
				channelId: "telegram",
				enabled: account.enabled !== false,
				configured: !!account.botToken,
				running: status?.running ?? false,
				username: accountManager.getBotUsername(account.accountId)
			};
		},
		probeAccount: async ({ account, timeoutMs }) => {
			const bot = accountManager.getBot(account.accountId);
			if (!bot) throw new Error("Bot not initialized");
			try {
				const { signal, dispose } = createTimeoutAbortSignal(Math.min(Math.max(timeoutMs ?? 1e4, 3e3), 6e4));
				try {
					const me = await bot.api.getMe(signal);
					return {
						ok: true,
						username: me.username,
						id: me.id
					};
				} finally {
					dispose();
				}
			} catch (err) {
				return {
					ok: false,
					error: String(err)
				};
			}
		},
		buildAccountSnapshot: async ({ account }) => {
			const status = accountManager.getStatus(account.accountId);
			return {
				accountId: account.accountId,
				channelId: "telegram",
				enabled: account.enabled !== false,
				configured: !!account.botToken,
				status: status?.running ? "running" : "stopped"
			};
		},
		resolveAccountState: ({ account, configured, enabled }) => {
			if (!configured) return "offline";
			if (!enabled) return "disabled";
			return accountManager.getStatus(account.accountId)?.running ? "online" : "offline";
		}
	};
}
//#endregion
export { createTelegramStatusAdapter };

//# sourceMappingURL=status-adapter.js.map