import { getSession } from "../lib/neo4j.js";
export async function workGet(taskId, accountId) {
    const session = getSession();
    try {
        // Fetch the task node
        const taskResult = await session.run(`MATCH (t:Task {taskId: $taskId, accountId: $accountId}) RETURN t`, { taskId, accountId });
        if (taskResult.records.length === 0)
            return null;
        const t = taskResult.records[0].get("t").properties;
        // Fetch all outgoing relationships
        const relResult = await session.run(`MATCH (t:Task {taskId: $taskId, accountId: $accountId})-[r]->(target)
       RETURN type(r) AS relType, labels(target) AS targetLabels, elementId(target) AS targetId,
              target.name AS targetName, target.givenName AS targetGivenName,
              target.taskId AS targetTaskId`, { taskId, accountId });
        const relationships = relResult.records.map((rec) => {
            const targetLabels = rec.get("targetLabels");
            const targetLabel = targetLabels[0] ?? "Unknown";
            const targetId = rec.get("targetId");
            // Best-effort name resolution across node types
            const targetName = rec.get("targetName") ??
                rec.get("targetGivenName") ??
                rec.get("targetTaskId") ??
                targetId;
            return {
                type: rec.get("relType"),
                targetLabel,
                targetId,
                targetName,
            };
        });
        const detail = {
            taskId: t.taskId,
            name: t.name,
            description: t.description,
            status: t.status,
            priority: t.priority,
            createdAt: t.createdAt,
            updatedAt: t.updatedAt,
            relationships,
        };
        if (t.dueDate)
            detail.dueDate = t.dueDate;
        if (t.notes)
            detail.notes = t.notes;
        return detail;
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=work-get.js.map