const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let __intlayer_cli = require("@intlayer/cli");
let __intlayer_types = require("@intlayer/types");
let zod_v3 = require("zod/v3");
zod_v3 = require_rolldown_runtime.__toESM(zod_v3);

//#region src/tools/cli.ts
const loadCLITools = async (server) => {
	server.tool("intlayer-build", "Build the dictionaries. List all content declarations files `.content.{ts,tsx,js,json,...}` to update the content callable using the `useIntlayer` hook.", {
		watch: zod_v3.default.boolean().optional().describe("Watch for changes"),
		baseDir: zod_v3.default.string().optional().describe("Base directory"),
		env: zod_v3.default.string().optional().describe("Environment"),
		envFile: zod_v3.default.string().optional().describe("Environment file"),
		verbose: zod_v3.default.boolean().optional().describe("Verbose output"),
		prefix: zod_v3.default.string().optional().describe("Log prefix")
	}, async ({ watch, baseDir, env, envFile, verbose, prefix }) => {
		try {
			const log = {};
			if (verbose) log.mode = "verbose";
			if (prefix) log.prefix = prefix;
			await (0, __intlayer_cli.build)({
				watch,
				configOptions: {
					baseDir,
					env,
					envFile,
					override: { log }
				}
			});
			return { content: [{
				type: "text",
				text: "Build successful."
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Build failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("intlayer-fill", "Fill the dictionaries with missing translations / review translations using Intlayer servers", {
		sourceLocale: zod_v3.default.nativeEnum(__intlayer_types.Locales.ALL_LOCALES).optional().describe("Source locale"),
		outputLocales: zod_v3.default.union([zod_v3.default.nativeEnum(__intlayer_types.Locales.ALL_LOCALES), zod_v3.default.array(zod_v3.default.nativeEnum(__intlayer_types.Locales.ALL_LOCALES))]).optional().describe("Output locales"),
		file: zod_v3.default.union([zod_v3.default.string(), zod_v3.default.array(zod_v3.default.string())]).optional().describe("File path"),
		mode: zod_v3.default.enum(["complete", "review"]).optional().describe("Fill mode"),
		keys: zod_v3.default.union([zod_v3.default.string(), zod_v3.default.array(zod_v3.default.string())]).optional().describe("Keys to include"),
		excludedKeys: zod_v3.default.union([zod_v3.default.string(), zod_v3.default.array(zod_v3.default.string())]).optional().describe("Keys to exclude"),
		pathFilter: zod_v3.default.union([zod_v3.default.string(), zod_v3.default.array(zod_v3.default.string())]).optional().describe("Path filter"),
		gitOptions: zod_v3.default.object({
			gitDiff: zod_v3.default.boolean().optional(),
			gitDiffBase: zod_v3.default.string().optional(),
			gitDiffCurrent: zod_v3.default.string().optional(),
			uncommitted: zod_v3.default.boolean().optional(),
			unpushed: zod_v3.default.boolean().optional(),
			untracked: zod_v3.default.boolean().optional()
		}).optional().describe("Git options"),
		aiOptions: zod_v3.default.object({
			provider: zod_v3.default.string().optional(),
			temperature: zod_v3.default.number().optional(),
			model: zod_v3.default.string().optional(),
			apiKey: zod_v3.default.string().optional(),
			customPrompt: zod_v3.default.string().optional(),
			applicationContext: zod_v3.default.string().optional()
		}).optional().describe("AI options")
	}, async (props) => {
		try {
			const { gitOptions,...rest } = props;
			const fillOptions = {
				...rest,
				gitOptions: void 0
			};
			if (gitOptions) {
				const { gitDiff, uncommitted, unpushed, untracked,...restGit } = gitOptions;
				const mode = [];
				if (gitDiff) mode.push("gitDiff");
				if (uncommitted) mode.push("uncommitted");
				if (unpushed) mode.push("unpushed");
				if (untracked) mode.push("untracked");
				fillOptions.gitOptions = {
					...restGit,
					mode
				};
			}
			await (0, __intlayer_cli.fill)(fillOptions);
			return { content: [{
				type: "text",
				text: "Fill successful."
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Fill failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("intlayer-push", "Push local dictionaries to the server", {
		deleteLocaleDictionary: zod_v3.default.boolean().optional().describe("Delete local dictionary after push"),
		keepLocaleDictionary: zod_v3.default.boolean().optional().describe("Keep local dictionary after push"),
		dictionaries: zod_v3.default.array(zod_v3.default.string()).optional().describe("List of dictionaries to push"),
		gitOptions: zod_v3.default.object({
			gitDiff: zod_v3.default.boolean().optional(),
			gitDiffBase: zod_v3.default.string().optional(),
			gitDiffCurrent: zod_v3.default.string().optional(),
			uncommitted: zod_v3.default.boolean().optional(),
			unpushed: zod_v3.default.boolean().optional(),
			untracked: zod_v3.default.boolean().optional()
		}).optional().describe("Git options")
	}, async (props) => {
		try {
			const { gitOptions,...rest } = props;
			const pushOptions = {
				...rest,
				gitOptions: void 0
			};
			if (gitOptions) {
				const { gitDiff, uncommitted, unpushed, untracked,...restGit } = gitOptions;
				const mode = [];
				if (gitDiff) mode.push("gitDiff");
				if (uncommitted) mode.push("uncommitted");
				if (unpushed) mode.push("unpushed");
				if (untracked) mode.push("untracked");
				pushOptions.gitOptions = {
					...restGit,
					mode
				};
			}
			await (0, __intlayer_cli.push)(pushOptions);
			return { content: [{
				type: "text",
				text: "Push successful."
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Push failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("intlayer-pull", "Pull dictionaries from the CMS", {
		dictionaries: zod_v3.default.array(zod_v3.default.string()).optional().describe("List of dictionaries to pull"),
		newDictionariesPath: zod_v3.default.string().optional().describe("Path to save new dictionaries")
	}, async (props) => {
		try {
			await (0, __intlayer_cli.pull)(props);
			return { content: [{
				type: "text",
				text: "Pull successful."
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Pull failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("intlayer-content-list", "List the content declaration (.content.{ts,tsx,js,json,...}) files present in the project. That files contain the multilingual content of the application and are used to build the dictionaries.", { configOptions: zod_v3.default.object({
		baseDir: zod_v3.default.string().optional(),
		env: zod_v3.default.string().optional(),
		envFile: zod_v3.default.string().optional(),
		override: zod_v3.default.object({ log: zod_v3.default.object({
			prefix: zod_v3.default.string().optional(),
			verbose: zod_v3.default.boolean().optional()
		}).optional() }).optional()
	}).optional().describe("Configuration options") }, async (props) => {
		try {
			const rows = (0, __intlayer_cli.listContentDeclarationRows)(props);
			return { content: [{
				type: "text",
				text: JSON.stringify(rows, null, 2)
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Content list failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("intlayer-content-test", "Test if there are missing translations in the content declaration files. That files contain the multilingual content of the application and are used to build the dictionaries.", { configOptions: zod_v3.default.object({
		baseDir: zod_v3.default.string().optional(),
		env: zod_v3.default.string().optional(),
		envFile: zod_v3.default.string().optional(),
		override: zod_v3.default.object({ log: zod_v3.default.object({
			prefix: zod_v3.default.string().optional(),
			verbose: zod_v3.default.boolean().optional()
		}).optional() }).optional()
	}).optional().describe("Configuration options") }, async (props) => {
		try {
			const missingTranslations = (0, __intlayer_cli.listMissingTranslations)(props?.configOptions);
			return { content: [{
				type: "text",
				text: JSON.stringify(missingTranslations, null, 2)
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Content test failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
};

//#endregion
exports.loadCLITools = loadCLITools;
//# sourceMappingURL=cli.cjs.map