from typing import Dict

from dependencyinjection import AnyType, DependencyContext
from messageprocessor import MessageMessageProcessorBuilder, MessageProcessor


class DiMessageMessageProcessorBuilder(MessageMessageProcessorBuilder):
    def __init__(
        self,
        dependency_context: DependencyContext,
        processor_definitions: Dict[int, AnyType]
    ):
        self.dependency_context = dependency_context
        self.processor_definitions = processor_definitions

    def build_message_processor(self, token: int) -> MessageProcessor:
        return self.dependency_context.get_instance(self.processor_definitions[token])

    def build_message_processor_dict(self) -> Dict[int, MessageMessageProcessorBuilder]:
        ret = {}
        for key in self.processor_definitions.keys():
            ret[key] = self
        return ret
