import { getSession } from "../lib/neo4j.js";
import { trashNode } from "../../../../../lib/graph-trash/dist/index.js";
import { withWriteEvent } from "../lib/log-ingest.js";
export async function profileDelete(params) {
    return withWriteEvent({ tool: "profile-delete", accountId: params.accountId, labels: ["Preference"], name: `${params.category}.${params.key}` }, () => profileDeleteImpl(params));
}
async function profileDeleteImpl(params) {
    const { accountId, userId, category, key } = params;
    const session = getSession();
    try {
        const lookup = await session.run(`MATCH (up:UserProfile {accountId: $accountId, userId: $userId})-[:HAS_PREFERENCE]->(pref:Preference {category: $category, key: $key})
       WHERE NOT pref:Trashed
       RETURN elementId(pref) AS eid LIMIT 1`, { accountId, userId, category, key });
        if (lookup.records.length === 0) {
            return { deleted: false, alreadyTrashed: false, category, key };
        }
        const eid = lookup.records[0].get("eid");
        const result = await trashNode({
            session,
            accountId,
            elementId: eid,
            by: "profile-delete",
        });
        return {
            deleted: result.trashed,
            alreadyTrashed: result.alreadyTrashed,
            category,
            key,
        };
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=profile-delete.js.map