Dependence of a selection list on an attribute

We have an "Invoice" class, which contains documents that belong to either the "Template" or the "Receipt" category (simple selection from the list of categories).

A document in the "Invoice" class is always assigned to a project (simple selection from the list of projects). A project can be a main project or a follow-up project (Boolean attribute).

Now there is the challenge that documents in the "Template" category can only be assigned to main projects. A document in the category "Receipt", on the other hand, can be assigned to a project regardless of whether it is a main or follow-up project. So I would need a filter for project selection that depends on the category.

Unfortunately, I can't think of a solution for how to implement this. Does anyone have an idea how I can relay this?