Have you seen this thread about flattening nested optionals?
Without knowing the rest of use-case, on its face this description sounds like an exceptionally-complicated design. Have you considered simplifying your architecture so you don’t need to do this sort of thing at all?