Changing functions from router to repeater

Good morning to all

I am trying to make a local WLAN with a main router and three other repeaters. I want to create an automated procedure where, when the main goes offline, the next takes its place and so on in hierarchical order. I am already doing it manually but it would be nice to automate it and do it faster

Any ideas?
Thank you in advanced

Thank you for the answer. I am not so familiar with OpenWRT but I have a good knowledge of networks and have no problem with command line.
This a good solution if I had the routers connected through cables. My problem is that there is no cabling here. Each of the routers has not also to connect to the main through WiFi but also retransmit the signal to one more router. That's why I asked about router and repeaters

Unless I misunderstood something, what you are trying to achieve is not easy to implement.
On the main router you have the uplink to the internet, right?
So if the main router goes offline, automation cannot move the uplink cable to the next repeater.

No. I don't want to have internet at all. I want a closed network with all the connections being wireless. I just have dhcp server and broadcasting the SSID on the main router. The other three must supply the devices with the same SSID, IP's from the DHCP server. In case the main goes down then I need the second to change role from repeater to main and take over the job from the main router. I get that is difficult and probably need some heavy scripting for something like that.
The network is going to be something like this

So no internet no nothing. Just a router connecting multiple devices. So if the central one goes I need one of the others to take over.

I don't think that the repeaters will stop working if the main goes offline.
Regarding the dhcp server, you could assign a lengthy lease time. If that is not enough you can run dhcp servers on each repeater. Use different pools on each dhcp server and make sure they offer the same dhcp options.