from common import TipBuilderCommon
from pos_model import Order, SaleItem
from typing import Dict, Any

from _ContextKeys import ContextKeys
from _SatXmlPartBuilder import SatXmlPartBuilder


class DetTipBuilder(SatXmlPartBuilder):

    def __init__(self, det_builder, tip_config, tip_builder_common):
        # type: (SatXmlPartBuilder, dict, TipBuilderCommon) -> None
        self.det_builder = det_builder
        self.tip_config = tip_config
        self.tip_builder_common = tip_builder_common

    def build_xml(self, order, context):
        # type: (Order, Dict[unicode, Any]) -> unicode
        xml = ""
        tip_items = self.tip_builder_common.get_tip_items(order)
        for tip_item in tip_items:
            context[ContextKeys.current_sale_item] = tip_item
            xml += self.det_builder.build_xml(order, context)
            context[ContextKeys.item_no] += 1
        return xml
