from .agent_vd_algorithms import (AgentVulnerabilitiesMC,
                                  AgentVulnerabilitiesMC2, BanditAlgos,
                                  VulnerableAgentMC1, VulnerableAgentMC2)


class VD():
    def __init__(self, vd_config_obj, world_obj):
        self.vd_config_obj = vd_config_obj
        self.world_obj = world_obj

    def get_class(self, name):
        components = name.split('.')

        mod = __import__(components[0])
        for comp in components[1:]:
            mod = getattr(mod, comp)
        return mod

    def add_target_name(self):
        path = ''
        if (self.vd_config_obj.target.lower() == 'agent'):
            path = 'agent_vd_algorithms'

        else:
            raise Exception('Input valid target')

        return path

    def get_algorithm(self):

        class_path = 'vulnerability_detection' + '.' + self.add_target_name(
        ) + '.' + self.vd_config_obj.algorithm
        algorithm_class = self.get_class(class_path)

        return algorithm_class

    def run_vul_detection(self):
        algorithm_class = self.get_algorithm()
        algo_object = algorithm_class(self.world_obj,
                                      self.vd_config_obj.parameter_dict)
        algo_object.run_detection()
        self.run_output(algo_object)

    def run_output(self, algo_object):
        if (self.vd_config_obj.output_mode == 'Default'
                or self.vd_config_obj.output_mode == ''):
            algo_object.print_default_output(10)

    def run_preprocess(self):
        pass

    def run_postprocess(self):
        pass
