"""Klasa pomocnicza do konwertowania naglowka na element drzewa xml i klasy header 
"""
from Mapa_PU.swdl.model.swdl.header import Header
from Mapa_PU.swdl.model.scheme import TreeElement
from Mapa_PU.swdl.model.tags import Tags
from datetime import date

"""Klasa pomocnicza konwertująca obiekt header na Xml i odwrotnie
"""
class HeaderConverter():
    
    def parsuj_header(self,xml):
        ##Generuje naglowek na podstawie drzewa xml
        return header()
        
    def create_header(self,header):
        ##Buduje naglowek w formie drzewa xml
        try:
            head=TreeElement(Tags.HEADER.value)
            head.append(TreeElement(Tags.SWDL_VERSION.value,header.version))
            address_data=TreeElement(Tags.DATA_SOURCE.value)
            address_data.append(TreeElement(Tags.UNIT_NAME.value,header.unit_name))
            address_data.append(TreeElement(Tags.UNIT_ADDRESS.value,header.unit_address))
            head.append(address_data)
            personal_data=TreeElement(Tags.RESPONSIBLE_PERSON.value)
            personal_data.append(TreeElement(Tags.POSITION.value,header.position))
            personal_data.append(TreeElement(Tags.NAME.value,header.name))
            personal_data.append(TreeElement(Tags.EMAIL.value,header.email))
            head.append(personal_data)
            head.append(TreeElement(Tags.EXPORT_DATE.value,str(date.today())))
#             
            return head
            
        except Exception as e:
            raise e
    