/**
 * Scan public agent conversations for waitlist extraction.
 *
 * Queries all public conversations and returns structured JSON
 * containing conversation IDs and user messages. This output
 * feeds an LLM extraction step (via a workflow) that identifies
 * contact details and discovery intelligence.
 *
 *   NEO4J
 *     │
 *     ├─ Conversation {agentType: 'public'}
 *     │    └─ Message {role: 'user'} (ordered by createdAt)
 *     │
 *     v
 *   STRUCTURED JSON
 *     { conversations: [{ conversationId, messages, createdAt }] }
 */
import { getSession } from "../lib/neo4j.js";
export async function waitlistScan(accountId) {
    const session = getSession();
    try {
        const result = await session.run(`MATCH (c:Conversation {agentType: 'public', accountId: $accountId})
       <-[:PART_OF]-(m:Message {role: 'user'})
       WITH c, m ORDER BY m.createdAt ASC
       RETURN c.conversationId AS conversationId,
              collect(m.content) AS messages,
              c.createdAt AS createdAt
       ORDER BY createdAt ASC`, { accountId });
        const conversations = result.records.map((r) => ({
            conversationId: r.get("conversationId"),
            messages: r.get("messages"),
            createdAt: (() => {
                const val = r.get("createdAt");
                if (!val)
                    return null;
                if (typeof val === "string")
                    return val;
                if (typeof val.toString === "function")
                    return val.toString();
                return null;
            })(),
        }));
        const totalMessages = conversations.reduce((sum, c) => sum + c.messages.length, 0);
        return { conversations, totalMessages };
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=waitlist-scan.js.map