from typing import Type, List

from edpdependencyinjection import DependencyContext
from messageprocessor import (
    MessageProcessorExecutorFactory,
    MessageProcessorCallback,
    DefaultMessageProcessorExecutor
)


class DiMessageProcessorExecutorFactory(MessageProcessorExecutorFactory):
    def __init__(
        self,
        dependency_context: DependencyContext,
        callback_definitions: List[Type[MessageProcessorCallback]]
    ):
        self.dependency_context = dependency_context
        self.callback_definitions = callback_definitions

    def build_executor(self, message_processor):
        return DefaultMessageProcessorExecutor(
            message_processor,
            callbacks=[
                self.dependency_context.get_instance(callback_def)
                for callback_def in self.callback_definitions
            ]
        )
