import { getSession } from "../lib/neo4j.js";
/**
 * memory-node-exists — deterministic singleton-existence check (Task 442).
 *
 * The hybrid-ranking memory-search returns "no results" for an installer-seeded
 * singleton whose content properties are still empty (e.g. a :LocalBusiness
 * with no name/description yet), and the agent then claims the node does not
 * exist. This primitive bypasses ranking and answers the literal question
 * "does a node with this label exist for this account?" with a single Cypher
 * MATCH on a property-indexed lookup.
 *
 * Scope is narrow by design: only installer-seeded singleton root labels are
 * on the allow-list. Free-form label input is refused and pointed back at
 * memory-search for ranked discovery. General-purpose Cypher reads stay in
 * database-operator.
 */
export const ALLOWED_LABELS = [
    "LocalBusiness",
    "AdminUser",
    "UserProfile",
    "Person",
];
const CYPHER_BY_LABEL = {
    LocalBusiness: "MATCH (n:LocalBusiness { accountId: $aid }) RETURN elementId(n) AS elementId, labels(n) AS labels LIMIT 1",
    AdminUser: "MATCH (n:AdminUser { accountId: $aid }) RETURN elementId(n) AS elementId, labels(n) AS labels LIMIT 1",
    UserProfile: "MATCH (n:UserProfile { accountId: $aid }) RETURN elementId(n) AS elementId, labels(n) AS labels LIMIT 1",
    Person: "MATCH (n:Person { accountId: $aid }) RETURN elementId(n) AS elementId, labels(n) AS labels LIMIT 1",
};
export async function memoryNodeExists({ accountId, label, }) {
    const cypher = CYPHER_BY_LABEL[label];
    const session = getSession();
    try {
        const result = await session.run(cypher, { aid: accountId });
        if (result.records.length === 0) {
            return { exists: false, elementId: null, labels: null };
        }
        const record = result.records[0];
        const elementId = record.get("elementId");
        const labels = record.get("labels");
        return { exists: true, elementId, labels };
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=memory-node-exists.js.map