How to set up advanced firewall in windows

Does windows os even have advanced firewall configuration? and if so how can i set up an advanced windows firewall settings in windows with policies such that it allows some open ports given an event has occured, user logged in/ out, detected a lot of ports being scanned among others
