Just a quick comment. The segments and segmentations are not designed to work the way you are exposing. May be you’ll end up with a working solution. My opinion is that you are writing code over and over again, so that someone does not recreate a deleted segment over and over again. Try to convince your users to follow the designed workflow.
Good luck and regards.