from typing import List, Dict, Any
from pos_model import Order

from _SatXmlPartBuilder import SatXmlPartBuilder


class InfCfeBuilder(SatXmlPartBuilder):
    cnf_random = ""
    cdv = ""

    def __init__(
        self,               # type: InfCfeBuilder
        part_builders,      # type: List[SatXmlPartBuilder]
        layout_version,     # type: str
    ):
        # type: (...) -> None

        self.part_builders = part_builders
        self.layout_version = layout_version

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

        inner_xml = ""
        for part_builder in self.part_builders:
            inner_xml += part_builder.build_xml(order, context)

        infcfe_xml = "<infCFe versaoDadosEnt='{}'>".format(self.layout_version)
        infcfe_xml += inner_xml
        infcfe_xml += "</infCFe>"

        return infcfe_xml
