from functools import cache

import cvc5.pythonic as cvc5
import z3


@cache
def _convert_sort(sort: cvc5.SortRef) -> z3.SortRef:
    if sort.eq(cvc5.BoolSort()):
        return z3.BoolSort()
    elif sort.eq(cvc5.IntSort()):
        return z3.IntSort()
    else:
        return z3.DeclareSort(sort.name())


@cache
def convert(const: cvc5.Const) -> z3.Const:
    return z3.Const(str(const), _convert_sort(const.sort()))
