import { getSession } from "../lib/neo4j.js";
import { notTrashed } from "../../../../../lib/graph-trash/dist/index.js";
export async function workflowGet(workflowId, accountId) {
    const session = getSession();
    try {
        const result = await session.run(`MATCH (w:Workflow {workflowId: $workflowId, accountId: $accountId})
       WHERE ${notTrashed("w")}
       OPTIONAL MATCH (w)-[:HAS_STEP]->(s:WorkflowStep) WHERE ${notTrashed("s")}
       RETURN w, collect(s) AS steps`, { workflowId, accountId });
        if (result.records.length === 0)
            return null;
        const record = result.records[0];
        const w = record.get("w").properties;
        const stepsRaw = record.get("steps");
        const steps = stepsRaw
            .map((s) => ({
            stepId: s.properties.stepId,
            type: "tool",
            plugin: s.properties.plugin ?? "",
            tool: s.properties.tool ?? "",
            params: s.properties.params
                ? JSON.parse(s.properties.params)
                : null,
            dependsOn: s.properties.dependsOn
                ? JSON.parse(s.properties.dependsOn)
                : null,
            onFailure: s.properties.onFailure ?? "abort",
            retryLimit: s.properties.retryLimit ?? null,
            outputKey: s.properties.outputKey ?? null,
            position: s.properties.position ?? 0,
            label: s.properties.label,
        }))
            .sort((a, b) => a.position - b.position);
        return {
            workflowId: w.workflowId,
            name: w.name,
            description: w.description,
            status: w.status,
            steps,
            createdAt: w.createdAt,
            updatedAt: w.updatedAt,
        };
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=workflow-get.js.map