I am trying to wrap my head around how to handle this use case.

I have a user model that has a unique db field (email). I am also using soft deletes.

I need to handle three cases:

1) The user model is updated. At the moment my validation stops the user from being updated, because ofcourse this email already exists. I think this is easily solved by ignoring the email validation if the email has not been changed.

2) A different user model is updated and the email is changed to another email already present in the db.

3) A new model is created and the email is already present in the db.

All the above scenarios must also take into account soft deleted models.

Would someone have some advice on how to structure this?