What causes gastritis/ulcers?

Apart from the h.pylori bacteria, NSAIDS, or alcohol abuse, is there any reason as to why someone develops gastritis? Is it just our bad luck? Genetic? Stress?

I’m trying to decipher what caused my gastritis, was it my diet? I constantly ate spicy and acidic foods. I am not an alcoholic, although I would get black out every so often. I rarely took NSAIDs, or any medication for that matter. I was on Ozempic for a few months, however I started developing gastritis symptoms months after stopping. I feel like I didn’t do any of the things that usually trigger this condition problematically, maybe it was a combination of all these things.

Has anyone asked their doctor and got any surprising answers?