import { getSession } from "../lib/neo4j.js";
import { int } from "neo4j-driver";
export async function workflowList(params) {
    const { accountId, status, limit = 50 } = params;
    let whereClause = "";
    if (status) {
        whereClause = " AND w.status = $status";
    }
    const query = `
    MATCH (w:Workflow {accountId: $accountId})
    WHERE true${whereClause}
    OPTIONAL MATCH (w)-[:HAS_STEP]->(s:WorkflowStep)
    RETURN w, count(s) AS stepCount
    ORDER BY w.updatedAt DESC
    LIMIT $limit`;
    const session = getSession();
    try {
        const result = await session.run(query, {
            accountId,
            status,
            limit: int(limit),
        });
        return result.records.map((rec) => {
            const w = rec.get("w").properties;
            const stepCount = rec.get("stepCount");
            return {
                workflowId: w.workflowId,
                name: w.name,
                description: w.description,
                status: w.status,
                stepCount: typeof stepCount === "object" && "toNumber" in stepCount
                    ? stepCount.toNumber()
                    : Number(stepCount),
                createdAt: w.createdAt,
                updatedAt: w.updatedAt,
            };
        });
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=workflow-list.js.map