from logging import getLogger
from typing import Dict, Union, Type
from unittest import TestCase

from dependencyinjection import DependencyLoader
from dihttpmessageprocessor import AutoMappedWebApi, AutoMappedDiRouterProcessorBuilder
from messageprocessor import MessageProcessor
from simplehttprouter import Route

import edpopenapibuilder
import testhttpmodule
from edpopenapibuilder.interactor import AutoOpenApiYamlBuilderInteractor
from edpopenapibuilder.interactor.dto import AutoOpenApiYamlBuilderRequest

_LOGGER = getLogger(__name__)

class TestOpenApiYamlInteractor(TestCase):
    def setUp(self):
        self.dependencies_loader = DependencyLoader()
        self.dependencies_loader.load_modules(
            modules=[
                testhttpmodule,
                edpopenapibuilder
            ],
        )

    def _get_router_builder(
        self,
        route_definition: Dict[Route, Union[Type[MessageProcessor], AutoMappedWebApi]] = None
    ) -> AutoMappedDiRouterProcessorBuilder:
        router_builder = AutoMappedDiRouterProcessorBuilder(
            dependency_context=self.dependencies_loader.build_context(),
            route_definition=route_definition,
        )
        return router_builder

    def test_execute(self):
        router_processor_builder = self._get_router_builder()
        interactor = AutoOpenApiYamlBuilderInteractor(
            router_processor_builder=router_processor_builder
        )
        result = interactor.execute(
            request=AutoOpenApiYamlBuilderRequest()
        )
        _LOGGER.info(f"\n{result}")
