from typing import Dict, Any
from pos_model import Order
from _SatXmlPartBuilder import SatXmlPartBuilder


class TotalBuilder(SatXmlPartBuilder):
    def __init__(self, tax_builder):
        self.tax_builder = tax_builder

    def build_xml(self, order, context):
        # type: (Order, Dict[unicode, Any]) -> unicode

        total_taxes = self.tax_builder.ibpt_tax_calculator(order.order_picture_xml)
        total_tax_amount = float(total_taxes['nacionalfederal']['value']) + float(total_taxes['estadual']['value'])
        return "<total><vCFeLei12741>{0:.02f}</vCFeLei12741></total>".format(total_tax_amount)
