"""mouł odpowiedziałny za tworzenie obiektów SWDL
"""

from Mapa_PU.swdl.kontroler.swdl_helper import SwdlHelper
from Mapa_PU.swdl.kontroler.swdl_helper_xml import SwdlHelperXml
from Mapa_PU.swdl.kontroler.xml_converter import XmlConverter
from Mapa_PU.swdl.model.swdl.swdl import Swdl


"""Klasa twzorząca obiekt swdl
"""
class SwdlCreator():
    def __init__(self,SwdlHelper,SwdlHelperXml,XmlConverter):
        self.__swdl_helper=SwdlHelper
        self.__swdl_helper_xml=SwdlHelperXml
        self.__swdl_xml_converter=XmlConverter
    
    
    def create_swdl_object(self,unit_name,unit_address, position, name, phone_number, email,address_forest,state_date):
        ##tworzy obiekt SWDL do przekazania do utworzenia drzewa xml
        try:
            swdl=Swdl()
            swdl.header=self.__swdl_helper.create_header(unit_name,unit_address, position, name, phone_number, email)
            swdl.forest_data_desc=self.__swdl_helper.create_forest_data_desc(address_forest,state_date)
            swdl.subarea_data_list=self.__swdl_helper.create_subarea_data_list(address_forest)
            swdl.forest_global_data=self.__swdl_helper.create_forest_global_data(address_forest)
            swdl.forest_map_no_sf=self.__swdl_helper.create_forest_map_no_sf(address_forest)
            swdl.forest_natural_values=self.__swdl_helper.create_forest_natural_values(address_forest)
            return swdl
        except Exception as e:
            raise e
        
    def create_swdl_from_xml(self,xml):
        """Tworzy obiekt swdl z drzewa xml
        :param xml; dane w postaci drzewa swdl
        """
        try:
            self.__swdl_xml_converter.load(xml)
            swdl=Swdl()
            swdl.subarea_data_list=self.__swdl_helper_xml.create_subarea_data_list(self.__swdl_xml_converter.root)
            swdl.forest_global_data=self.__swdl_helper_xml.create_forest_global_data(self.__swdl_xml_converter.root)
            swdl.forest_data_desc=self.__swdl_helper_xml.create_forest_data_desc(self.__swdl_xml_converter.root)
            swdl.forest_map_no_sf=self.__swdl_helper_xml.create_forest_map_no_sf(self.__swdl_xml_converter.root)
            swdl.forest_natural_values=self.__swdl_helper_xml.create_forest_natural_values(self.__swdl_xml_converter.root)
            return swdl
        except Exception as e:
            raise e
            