from logging import getLogger
from unittest import TestCase

from edpopenapibuilder.builder.helper import build_from_message_handler_builder
from edpopenapibuilder.model import ServerModel, ServerVariableModel
from samplehttpmodule.messagehandlerbuilder import (
    DependencyInjectionSampleMessageHandlerBuilder,
    SampleMessageHandlerBuilder
)
from samplehttpmodule.route import add_descriptors

_LOGGER = getLogger(__name__)


class TestDependencyInjectionApiYamlBuilderInteractor(TestCase):
    def setUp(self):
        add_descriptors()

    def test_build_from_dependency_injection_message_handler_builder(self):
        message_handler_builder = DependencyInjectionSampleMessageHandlerBuilder()
        builder = build_from_message_handler_builder(message_handler_builder)
        server = ServerModel(
            url="http://example.com",
            description="server description",
        )
        server.add_variable("test_var", ServerVariableModel(description="Test Variable", default="test"))
        builder.get_model().add_server(server)
        print(builder.build_open_api_yaml())

    def test_build_yaml_from_message_handler_builder(self):
        message_handler_builder = SampleMessageHandlerBuilder()
        builder = build_from_message_handler_builder(message_handler_builder)
        print(builder.build_open_api_yaml())
