import threading
from DBConnection import postgresConnection

from typing import List

schedule = []

class transaction(object):

    total_diff = 0

    def __init__(self, pos: int):
        self.__action = threading.Thread()
        self.check = False
        self.pos = pos


    # i have used *args because i will maybe extend the transaction class
    # s.t. they can do multiple tasks.
    def setAction(self, action, *args):
        self.__action = threading.Thread(target=action, args=args)
        if "add" in str(action):
            transaction.total_diff += args[0][0]
        elif "sub" in str(action):
            transaction.total_diff -= args[0][0]

    def start(self):
        self.__action.start()

    def join(self):
        self.__action.join()

    def isAlive(self) -> bool:
        return self.__action.is_alive()

    def getAction(self):
        return self.__action
