import { getSession } from "../lib/neo4j.js";
/**
 * Delete a workflow and cascade to all related nodes:
 * WorkflowStep nodes, WorkflowRun nodes, and StepResult nodes.
 */
export async function workflowDelete(workflowId, accountId) {
    const session = getSession();
    try {
        const existing = await session.run(`MATCH (w:Workflow {workflowId: $workflowId, accountId: $accountId})
       RETURN w`, { workflowId, accountId });
        if (existing.records.length === 0) {
            throw new Error(`Workflow not found: ${workflowId}`);
        }
        // Cascade delete: steps, runs, step results, then the workflow itself
        await session.run(`MATCH (w:Workflow {workflowId: $workflowId, accountId: $accountId})
       OPTIONAL MATCH (w)-[:HAS_STEP]->(s:WorkflowStep)
       OPTIONAL MATCH (r:WorkflowRun)-[:RUN_OF]->(w)
       OPTIONAL MATCH (r)-[:HAS_RESULT]->(sr:StepResult)
       DETACH DELETE sr, r, s, w`, { workflowId, accountId });
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=workflow-delete.js.map