Can routeros detect when a wireguard connection is down so it can modify and try to use a different server?

I don’t have the best VPN provider and am wondering if via scripting it is possible to detect when wireguard goes down (this was a nightmare around the holidays) and then auto update:
An /ip route setting
2 /interface wireguard peers settings
An /interface wireguard setting