# -*- coding: utf-8 -*-
import os

from helper import config_logger, import_pydevd

from messagehandler import MessageHandler
from msgbus import MBEasyContext
from pos_model import OrderParser
from eventhandler import NTaxCalcEventHandler
from taxcalculator import TaxCalculatorService, GeneralTaxCalculator, OrderFormatter, TaxItemFormatter

REQUIRED_SERVICES = ""


def main():
    loader_path = os.environ["LOADERCFG"]
    import_pydevd(loader_path, 9175)

    config_logger(loader_path, 'NTaxCalc')
    mbcontext = MBEasyContext("NTaxCalc")

    message_handler = MessageHandler(mbcontext, "NTaxCalc", "NTaxCalc", REQUIRED_SERVICES)

    order_parser = OrderParser()

    general_tax_calculator = GeneralTaxCalculator(mbcontext)

    tax_item_formatter = TaxItemFormatter()
    order_formatter = OrderFormatter(tax_item_formatter)
    tax_calculator_service = TaxCalculatorService(order_parser, general_tax_calculator, order_formatter, mbcontext)

    event_handler = NTaxCalcEventHandler(mbcontext, tax_calculator_service)

    message_handler.set_event_handler(event_handler)

    message_handler.subscribe_sync_events(["TAXCALC", "TAX_CALC", "TAX_CALC_ITEM"])

    message_handler.handle_events()
