import { getSession } from "../lib/neo4j.js";
import { resolvePersonMatch } from "../lib/resolve-person.js";
import { trashNode } from "../../../../../lib/graph-trash/dist/index.js";
export async function contactDelete(params) {
    const { nodeId, email, telephone, reason, accountId } = params;
    const { matchClause, queryParams } = resolvePersonMatch({ nodeId, email, telephone }, accountId, { includeTrashed: true });
    const session = getSession();
    try {
        const lookup = await session.run(`${matchClause}
       RETURN elementId(p) AS eid,
              p.email AS email,
              p.telephone AS telephone,
              p:Trashed AS trashed`, queryParams);
        if (lookup.records.length === 0) {
            throw new Error("Contact not found");
        }
        const eid = lookup.records[0].get("eid");
        const personEmail = lookup.records[0].get("email");
        const personPhone = lookup.records[0].get("telephone");
        const identifier = personEmail ?? personPhone ?? nodeId ?? "unknown";
        const result = await trashNode({
            session,
            accountId: accountId,
            elementId: eid,
            by: "contact-delete",
            reason,
        });
        return {
            trashed: result.trashed,
            alreadyTrashed: result.alreadyTrashed,
            elementId: eid,
            identifier,
        };
    }
    finally {
        await session.close();
    }
}
//# sourceMappingURL=contact-delete.js.map