from pytanga.components import AbstractComponent


class addressFamilyIPv4UnicastComponent(AbstractComponent):

    def __init__(self,
                 auto_summary=None,
                 originate_default=None,
                 default_metric=None,
                 synchronization=None,
                 segment_routing_mpls=None
                 ):
        self._xmlns = {}
        self.attributes = self.setAttributes(auto_summary,
                                             originate_default,
                                             default_metric,
                                             synchronization,
                                             segment_routing_mpls)
        self.parent_xmlns = {}
        self._children: List[AbstractComponent] = []
        self.childrenData = []
        self.tag = 'ipv4-unicast'

    @property
    def xmlns(self):
        return self._xmlns

    @xmlns.setter
    def xmlns(self, xmlns):
        self._xmlns = xmlns

    def setAttributes(self,
                      auto_summary,
                      originate_default,
                      default_metric,
                      synchronization,
                      segment_routing_mpls):
        attributes = {}
        if(auto_summary):
            attributes['auto-summary'] = None
        if(originate_default):
            attributes['default-information'] = {'originate': None}
        if(synchronization):
            attributes['synchronization'] = None
        if(segment_routing_mpls):
            attributes['segment-routing'] = {'mpls': None}
        return attributes

    def add(self, component) -> None:
        self._children.append(component)

    def remove(self, component) -> None:
        self._children.remove(component)

    def is_composite(self) -> bool:
        return False

    def getXMLNS(self):
        childrenData = []
        for child in self._children:
            self.parent_xmlns.update(child.getXMLNS())
        return self.parent_xmlns

    def parse(self, serializer):
        self.childrenData = []
        self.getXMLNS()
        for child in self._children:
            self.childrenData.append(child.parse(serializer))
        return serializer.parse(self)
