//#region src/gateway/hono/routes/cron.ts
function registerCronRoutes(authenticated, deps) {
	const { service } = deps;
	authenticated.get("/api/cron", async (c) => {
		const jobs = await service.cronServiceInstance.listJobs();
		return c.json({ jobs });
	});
	authenticated.post("/api/cron", async (c) => {
		const { schedule, name, timezone, sessionTarget, agentId, workingDirectory, model, delivery, payload } = await c.req.json();
		if (!schedule || !payload) return c.json({ error: "Missing required fields: schedule, payload" }, 400);
		try {
			const result = await service.cronServiceInstance.addJob(schedule, {
				name,
				timezone,
				sessionTarget,
				...typeof agentId === "string" && agentId.trim() ? { agentId: agentId.trim() } : {},
				...typeof workingDirectory === "string" && workingDirectory.trim() ? { workingDirectory: workingDirectory.trim() } : {},
				model,
				delivery,
				payload
			});
			return c.json(result, 201);
		} catch (err) {
			return c.json({ error: err instanceof Error ? err.message : "Failed to add job" }, 400);
		}
	});
	authenticated.get("/api/cron/metrics", async (c) => {
		const metrics = await service.cronServiceInstance.getMetrics();
		return c.json(metrics);
	});
	authenticated.get("/api/cron/runs/history", async (c) => {
		const raw = c.req.query("limit");
		const limit = raw ? parseInt(raw, 10) : 50;
		const runs = await service.cronServiceInstance.getAllRunsHistory(Number.isFinite(limit) ? limit : 50);
		return c.json({ runs });
	});
	authenticated.get("/api/cron/:id", async (c) => {
		const id = c.req.param("id");
		const job = await service.cronServiceInstance.getJob(id);
		if (!job) return c.json({ error: "Job not found" }, 404);
		return c.json({ job });
	});
	authenticated.post("/api/cron/:id/toggle", async (c) => {
		const id = c.req.param("id");
		const { enabled } = await c.req.json();
		if (typeof enabled !== "boolean") return c.json({ error: "Missing required field: enabled" }, 400);
		const result = await service.cronServiceInstance.toggleJob(id, enabled);
		return c.json({ toggled: result });
	});
	authenticated.post("/api/cron/:id/run", async (c) => {
		const id = c.req.param("id");
		try {
			await service.cronServiceInstance.runJobNow(id);
			return c.json({ triggered: true });
		} catch (err) {
			return c.json({ error: err instanceof Error ? err.message : "Failed to run job" }, 400);
		}
	});
	authenticated.get("/api/cron/:id/history", async (c) => {
		const id = c.req.param("id");
		const raw = c.req.query("limit");
		const limit = raw ? parseInt(raw, 10) : 10;
		const history = await service.cronServiceInstance.getJobHistory(id, Number.isFinite(limit) ? limit : 10);
		return c.json({ history });
	});
	authenticated.patch("/api/cron/:id", async (c) => {
		const id = c.req.param("id");
		const body = await c.req.json();
		try {
			const result = await service.cronServiceInstance.updateJob(id, body);
			return c.json({ updated: result });
		} catch (err) {
			return c.json({ error: err instanceof Error ? err.message : "Failed to update job" }, 400);
		}
	});
	authenticated.delete("/api/cron/:id", async (c) => {
		const id = c.req.param("id");
		const result = await service.cronServiceInstance.removeJob(id);
		return c.json({ removed: result });
	});
}
//#endregion
export { registerCronRoutes };

//# sourceMappingURL=cron.js.map