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


class InfRespTecBuilder(NfceXmlPartBuilder):

    def __init__(
            self,
            software_developer  # type: SoftwareDeveloper
    ):
        # type: (...) -> None

        self.software_developer = software_developer

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

        xml = ""

        if self.software_developer.enabled is True:
            xml += "<infRespTec>"

            xml += "<CNPJ>{}</CNPJ>".format(self.software_developer.cnpj)
            xml += "<xContato>{}</xContato>".format(self.software_developer.contact)
            xml += "<email>{}</email>".format(self.software_developer.email)
            xml += "<fone>{}</fone>".format(self.software_developer.phone)

            if self.software_developer.id_csrt and self.software_developer.csrt:
                xml += "<idCSRT>{}</idCSRT>".format(self.software_developer.id_csrt)
                xml += "<hashCSRT>${HASH_CSRT}</hashCSRT>"

                context[ContextKeys.csrt] = self.software_developer.csrt
                context[ContextKeys.id_csrt] = self.software_developer.id_csrt

            xml += "</infRespTec>"

        return xml
