import time
import sys
import os
import json
import _thread
import importlib
from tools.executor import Executor
from tools.otherwise import Nothing

class ToolInitializer:
    def __init__(self):
        self.loaded_tools = {}

    def load(self, module_param, class_param):
        module = importlib.import_module(module_param)
        loaded_class_tool = getattr(module, class_param)
        self.loaded_tools[class_param] = loaded_class_tool

    def initialize(self, class_param, task_param) -> Executor:
        return self.loaded_tools[class_param](task_param)

    def build(self, module_param, class_param, task_param):
        try:
            if class_param not in self.loaded_tools:
                self.load(module_param, class_param)
            return self.initialize(class_param, task_param)
        except:
            return Nothing(task_param)
