import z3

import problems
from problems.z3_utils import fresh_const

from . import Sort, dijkstra_self_stabilizing_system, is_privileged, key_pre


def sanity(key: z3.FuncDeclRef = key_pre) -> z3.BoolRef:
    s = fresh_const(Sort)
    return z3.Exists(s, is_privileged(s, key))


def sanity_counterexample() -> z3.BoolRef:
    return z3.And(dijkstra_self_stabilizing_system(), z3.Not(sanity()))


@problems.mark(
    model=True,
    slow="cvc5-conversion",
    bruteforce_axiom=True,
    guided_axiom=True,
    popl25=True,
)
def dijkstra_self_stabilizing_sanity() -> z3.BoolRef:
    return sanity_counterexample()
