import clingo
import yaml
import threading
import os

class WrappedPropagateControl(object):
    def __init__(self, control, calls):
        self.control = control
        self.calls = calls

    def add_literal(self):
        call = {}
        call["name"] = "add_literal"
        call["args"] = []
        self.calls.append(call)
        return self.control.add_literal()

    def add_clause(self, lits, tag=False, lock=False):
        lits = list(lits)
        call = {}
        call["name"] = "add_clause"
        call["args"] = [lits[:], tag, lock]
        self.calls.append(call)
        if isinstance(self.control, clingo.PropagateInit):
            ret = self.control.add_clause(lits)
        else:
            ret = self.control.add_clause(lits, tag, lock)
        call["ret"] = ret
        return ret

    def add_watch(self, lit):
        call = {}