import os
import sys

from application.configurator import Configurator
from application.repository import MessageBusRepository
from eventhandlerbuilder import AuditEventConsumerEventHandler
from mbcontextmessagehandler import MbContextMessageBus

from helper import import_pydevd

reload(sys)
sys.setdefaultencoding("utf-8")


def main():
    # type: () -> None

    loader_path = os.environ["LOADERCFG"]
    import_pydevd(loader_path, 9136)

    configs = Configurator(loader_path)
    configs.configure_service_name()
    configs.configure_logger()

    configs.logger.info("Starting Pump Component...")

    event_handler = AuditEventConsumerEventHandler(configs)
    message_bus = MbContextMessageBus(event_handler.mbcontext)

    repository = MessageBusRepository(message_bus)
    configs.read_configurations(repository)

    event_handler.set_repository(repository)
    event_handler.build_interactors()
    event_handler.start()

    configs.logger.info("Finishing Pump Component...")


if __name__ == "__main__":
    main()
