#include "approval_control.h"
#include <cassert>
int main() {
    ApprovalControl c;
    assert(!c.modal());
    const auto old_press = c.generation;
    assert(c.receive({"one", "pi", "Edit file?", "/tmp/x", 120000}, 0));
    assert(c.release(true, old_press, 1).id.empty()); // held before overlay
    auto action = c.release(true, c.generation, 2);
    assert(action.id == "one" && action.approve);
    assert(c.release(false, c.generation, 3).id.empty()); // duplicate response is ignored
    assert(!c.finish("stale", "APPROVED", 4));
    assert(c.finish("one", "APPROVED", 4));
    assert(c.receive({"two", "codex", "Run command?", "pwd", 120000}, 5));
    assert(c.current() == nullptr && c.modal()); // one second feedback
    auto during_feedback = c.generation;
    c.tick(1004);
    assert(c.current()->id == "two");
    assert(c.release(true, during_feedback, 1005).id.empty());
    auto second = c.release(false, c.generation, 1006);
    assert(second.id == "two" && !second.approve);
    c.finish("two", "REJECTED", 1007); c.tick(2007);
    assert(!c.modal()); // page model never changed
    c.receive({"three", "pi", "Edit?", "x", 2100}, 2010);
    auto epoch=c.generation;
    assert(!c.tick(999999999) && c.modal());
    assert(c.release(true, epoch, 999999999).id == "three");
    c.finish("three", "CANCELLED", 999999999);
    c.receive({"four", "pi", "Edit?", "x", 4000}, 2200);
    c.disconnect();assert(!c.modal());
    assert(c.release(true, epoch, 2300).id.empty());
}
