Mental health struggles are common and of course pilots are not immune to these. From my experience the CAA are rightly careful but also helpful and reasonable when it comes to dealing with mental health issues. Certain SSRIs are allowed to be taken while flying but any others medications would need to be stopped before getting the medical. If you were unfortunate to have any recurrence of symptoms bothersome enough that you couldn’t fly the CAA would suspend the medical then require medical reports from specialists and full recovery before going back. It’s not necessarily a case of losing the medical and never getting it back again. As long as you recover and can show this then it’s possible to return to flying. I found the most helpful treatment to be cognitive behavioural therapy (CBT) with a psychologist so that you can recognise and analyse any negative thoughts and then reframe them to something more positive or rational. Also generally managing stress outside of work and not overdoing things is important.