

class DrawContext:
    currentComponentKey:str = ""
    currentComponentScheme: dict = {}
    path: str = ""
    propertyNameStack: list = []
    listLevel: int = 0

    def currentPropName(self) -> str: 
        return self.propertyNameStack[-1]

    def currentPropScheme(self) -> dict or None:
        scheme = self.currentComponentScheme
        for key in self.propertyNameStack:
            if key in scheme:
                scheme = scheme[key]
            elif key == "array":
                scheme = scheme["type"]
            else:
                return None
        return scheme

    def isInList(self) -> bool:
        return self.listLevel > 0

    def reset(self):
        self.currentComponentKey = ""
        self.path = ""
        self.propertyNameStack.clear()
        self.listLevel = 0
        self.drawingListItem = False

    def resetPath(self):
        self.path = ""

    def beforeDrawProperty(self, name:str):
        self.path += "/" + name
        self.propertyNameStack.append(name)
    
    def afterDrawProperty(self, name:str):
        self.path = self.path[:-len(name)-1]
        self.propertyNameStack.pop()
    
    def startList(self):
        self.listLevel += 1
    
    def endList(self):
        self.listLevel -= 1


currentDrawContext : DrawContext = None