from typing import Dict, Tuple

from messageprocessor import MessageProcessor
from simplehttprouter import Route, SimpleHttpRouter, FoundRoute
from ._RouterProcessorBuilder import RouterProcessorBuilder


class SimpleHttpRouterRouterProcessorBuilder(RouterProcessorBuilder):
    def __init__(self, route_processor):
        # type: (Dict[Route, MessageProcessor]) -> None
        self.route_processor = route_processor
        self.router = SimpleHttpRouter(route_processor.keys())

    def get_processor(self, route):
        # type: (Route) -> Tuple[FoundRoute, MessageProcessor]
        found_route = self.router.get_route(route)
        return found_route, self.route_processor[found_route.route]
