"""Describe a goal as data, propose two candidate programs, try both, and commit the one that solves."""

from judgment import Candidate, ExprData, Session, TacticData, TypeData, arrow, exists, implies


def main() raises:
    var s = Session()
    var T = s.declare_type("T")
    var R = s.symbol("R", arrow(T, s.prop_type()))
    var proof = s.theorem("witnessed")
    var a = proof.var("a", T)
    _ = proof.given("ra", R(a))
    var y = proof.bound_var("y", T)
    proof.goal(exists(y, R(y)))

    # A producer sees only data: the goal's path, revision, target, and context.
    var goal = proof.current_goal().data()
    print(goal.target().format(), goal.variables()[0], goal.premises()[0])

    # Two candidate programs, built without any session reference.
    var first = TacticData.split().then(TacticData.assumption())
    var second = TacticData.witness(ExprData.name("a")).then(TacticData.exact("ra"))
    var candidates = [Candidate(goal.path(), goal.revision(), first), Candidate(goal.path(), goal.revision(), second)]

    # Trials report without changing the draft; the first that solves is committed.
    for candidate in candidates:
        var report = proof.trial(proof.compile(candidate.tactic()))
        print(report.status())
        if report.status() == "solved":
            print(proof.by(candidate).status())
            break
    print(proof.finish())
