I'm looking for code to classify participants with depression using more complicated diagnostic criteria than I've used before with STATA.

The scale is the 9-item PHQ 9. Each item (phq_1 through phq_9) has a value of 0 - 3.

I need to identify participants based on meeting the following criteria:
Major Depression: phq_1 or phq_2 of at least 2 AND at least five items phq_1 through phq_9 of at least 2. (But if phq_9 is 1 or higher, it counts towards the five items).

Other Depression: phq_1 or phq_2 of at least 2 AND two, three, or four items phq_1 - phq_9 of at least 2. (Again, if phq_9 is 1 or higher, it counts towards the two, three or four items).

I would really appreciate tips or code on how to express these criteria. I'm stuck at:
gen mds = .
replace mds = 1 if

Thank you for any suggestions.