from typing import Dict, Any
from pos_model import Order
from _NfceXmlPartBuilder import NfceXmlPartBuilder
from _ContextKeys import ContextKeys


class InfIntermedBuilder(NfceXmlPartBuilder):

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

        delivery_partner = context[ContextKeys.delivery_partner]
        if delivery_partner is None:
            return ""

        partner_id = delivery_partner.get("partnerId")
        cnpj = delivery_partner.get("cnpj")
        xml = "<infIntermed><CNPJ>{0}</CNPJ><idCadIntTran>{1}</idCadIntTran></infIntermed>"
        return xml.format(cnpj, partner_id)
