This is almost exactly how the restricted replies plugin works
The only thing is doesn’t handle is (3). That will be extremely tricky to implement, because of all the reasons listed above.