from pos_model import (
    TaxItem,
    SaleItem,
)


class TaxItemFormatter(object):

    pattern = "<TaxItem lineNumber=\"{line_number}\" " \
              "level=\"{level}\" " \
              "itemId=\"{item_id}\" " \
              "partCode=\"{part_code}\" " \
              "taxRuleId=\"{tax_rule_id}\" " \
              "taxName=\"{tax_name}\" " \
              "taxIndex=\"{tax_index}\" " \
              "taxIncluded=\"{tax_included}\" " \
              "taxRate=\"{tax_rate}\" " \
              "baseAmountBD=\"{base_ammount_bd}\" " \
              "taxAmountBD=\"{tax_ammount_bd}\" " \
              "baseReducedAmount=\"{base_reduced_amount}\" " \
              "baseAmountAD=\"{base_ammount_ad}\" " \
              "taxAmountAD=\"{tax_ammount_ad}\"/>"

    def format_tax_item(
        self,       # type: TaxItemFormatter
        tax_item,   # type: TaxItem
        sale_item,  # type: SaleItem
    ):
        # type: (...) -> str

        if tax_item is None:
            raise ValueError("tax_item cannot be None")

        return self.pattern.format(
            line_number=sale_item.line_number,
            level=sale_item.level,
            item_id=sale_item.item_id,
            part_code=sale_item.part_code,
            tax_rule_id=tax_item.tax_rule_id,
            tax_name=tax_item.tax_name,
            tax_index=tax_item.tax_name + "|" + tax_item.tax_index,
            tax_included=tax_item.tax_included,
            tax_rate=tax_item.tax_rate,
            base_ammount_bd=tax_item.base_amount_bd,
            tax_ammount_bd=tax_item.tax_amount_bd,
            base_reduced_amount=tax_item.base_reduced_amount,
            base_ammount_ad=tax_item.base_amount_ad,
            tax_ammount_ad=tax_item.tax_amount_ad,
        )
