See WordPress/ai-provider-for-google#11 (comment) (cc @gziolo) - this is going to be helpful in reducing tedious code bits.
It's crucial to support $required and $optional modalities in the utility. Modality lists are considered unordered (as in "order doesn't matter"), so we only need to make sure to cover the combinations like that.