import { init_loader, loadConfig } from "../../../../config/loader.js";
import { bundledChannelPlugins } from "../../../../generated/bundled-channel-plugins.js";
import { existsSync } from "node:fs";
//#region src/cli/commands/doctor/checks/channel-plugins.ts
init_loader();
function toCheckResults(plugin, raw) {
	const pid = String(plugin.id);
	return raw.map((r) => ({
		id: `channel:${pid}:${r.id}`,
		label: `${pid}: ${r.label}`,
		status: r.status,
		message: r.message,
		hints: r.hints
	}));
}
async function checkChannelPlugins(ctx) {
	if (!existsSync(ctx.configPath)) return [];
	let cfg;
	try {
		cfg = loadConfig(ctx.configPath);
	} catch {
		return [];
	}
	const out = [];
	for (const plugin of bundledChannelPlugins) {
		const doctor = plugin.doctor;
		if (!doctor?.check) continue;
		try {
			const res = await doctor.check({ cfg });
			out.push(...toCheckResults(plugin, res));
		} catch (e) {
			const msg = e instanceof Error ? e.message : String(e);
			out.push({
				id: `channel:${plugin.id}:error`,
				label: `${String(plugin.id)}: doctor`,
				status: "warn",
				message: `Channel doctor check failed: ${msg}`,
				hints: []
			});
		}
	}
	return out;
}
//#endregion
export { checkChannelPlugins };

//# sourceMappingURL=channel-plugins.js.map