from pyboot.component import Component
from pyboot.stereotype import *
from pyboot.utils.log import Log
from pyboot.config import ConfigManager

class ComponentFactory:
    @staticmethod
    def create(component_type: str, name: str) -> Component:
        component_classes = get_component_classes(component_type=component_type)
        if component_classes is None:
            Log.error(f"Unsupported component type: {component_type}", True)

        if component_type == "COMPONENT":
            config = ConfigManager.get(component_type, name)
            cls = component_classes[config["source"]]
            component_obj = cls(config)
            component_obj.NAME = name
            component_obj.TYPE = component_type 
            return component_obj
        
        if name not in component_classes:
            Log.error(f"Unsupported component name: {name}", True)
        
        cls = component_classes[name]
        config = ConfigManager.get(component_type, name)
        return cls(config)
    