import path from "path";
import fs from "fs";
import yaml from "js-yaml";
//#region src/core/sla-engine.ts
const DEFAULT_RULES = [
	{
		priority: "urgent",
		resolveDays: 1
	},
	{
		priority: "high",
		resolveDays: 2
	},
	{
		priority: "normal",
		resolveDays: 5
	},
	{
		priority: "low",
		resolveDays: 10
	}
];
function loadSlaRules(dataDir) {
	const p = path.join(dataDir, ".agentic", "sla-rules.yaml");
	if (!fs.existsSync(p)) return DEFAULT_RULES;
	try {
		return yaml.load(fs.readFileSync(p, "utf-8"))?.rules ?? DEFAULT_RULES;
	} catch {
		return DEFAULT_RULES;
	}
}
function addDaysToDate(isoDate, days) {
	const [year, month, day] = isoDate.split("-").map(Number);
	const d = new Date(Date.UTC(year, month - 1, day));
	d.setUTCDate(d.getUTCDate() + days);
	return d.toISOString().slice(0, 10);
}
function calcSlaDue(createdDate, priority, rules) {
	return addDaysToDate(createdDate, (rules.find((r) => r.priority === priority) ?? { resolveDays: 5 }).resolveDays);
}
function isSlaBreach(ticket, today) {
	if (ticket.status === "resolved" || ticket.status === "closed") return false;
	if (!ticket.slaDue) return false;
	return ticket.slaDue < today;
}
async function checkSlaBreaches(dataDir, today) {
	const { listAllTickets } = await import("./ticket-writer-DsfpeLGZ.js");
	return (await listAllTickets(dataDir)).filter(({ ticket }) => isSlaBreach(ticket, today));
}
//#endregion
export { loadSlaRules as i, checkSlaBreaches as n, isSlaBreach as r, calcSlaDue as t };

//# sourceMappingURL=sla-engine-O-A1ntu_.js.map