NSWindowWillMiniaturizeNotification is one answer. It would be sent for each window. You could handle it with that.
You could also override:
- (void)miniaturizeAll:(id)sender
In an NSApplication category ( to avoid subclassing ) and call super if its ok to do so based on your conditions.
Don't call super if you want to prevent it. ( but do notify users visually )
You might even set the menu item inactive when conditions match your needs, if you create a property you can bind it to.