from targets import *
from targets.BankTarget import BankTarget

class TargetFactory:
    def createAllTargets(self):
        result = dict()
        glo = globals()  # Save globals so the dict does not change during execution of the script

        for key in glo:
            if(type(target) != 'class'):
                continue

            target = glo[key]
            if 'Target' in key:
                result[key] = target()
            elif 'Bank' in key and 'Target' not in key:
                targets = self.createBankTarget(target, key)
                result = {**result, **targets}
        # todo check with driver?
        return result

    def createBankTarget(self, target, key):
        bankTarget = target()
        targets = dict()
        targets[key] = bankTarget

        for target in bankTarget.targets:
            name = type(target).__name__
            targets[name] = target

        return targets
