How to merge node based on two potentially unique values

I want to make nodes labeled "person." Person nodes have two ids, id1 and id2, which I've made unique. These ids may also be empty (AKA not in the properties). When I'm adding a new person, I want to check that they don't have an id1 or id2 that are already in the database. If neither of them are in the database, the person node gets made as normal. If there's a node with one or both of them in the database, I just want that node. If there are two nodes, one with id1 and an empty id2, another with id2 and an empty id1, I want to merge those two nodes, combining all the relationships they have and making a new node with both id1 and id2. Overall just a headache of a problem and I don't know if it's even possible. Please let me know if I need to clarify anything, I'd highly appreciate some help on this!

Hi @ldj20

I think you can merge it with just Cypher or with APOC.
If you have three such data sets, what should happen in the merge?

(:Person {id1:"3",id2:""})
(:Person {id1:"4",id2:""})
(:Person {id1:"",id2:"5"})