# -*- coding: utf-8 -*-

from Mapa_PU.swdl.model.swdl.natural_values import NaturalValue 
from Mapa_PU.swdl.model.scheme import TreeElement,TreeElementOptional
from Mapa_PU.swdl.model.tags import Tags 

class ForestNaturalValuesConverter():
    """Klasa tworząca drzewo xml na podstawie obiektów ForestNaturalValue"""
    
    def create_forest_natural_values(self,natural_values:[]):
        """Metoda tworzy drzewo forestNaturalValues"""
        if len(natural_values)==0:
            return None
        natural_values_xml=TreeElement(Tags.FOREST_NATURAL_VALUES.value)
        for nvalue in natural_values:
            natural_value=TreeElement(Tags.NATURAL_VALUE.value)
            natural_value.append(TreeElement(Tags.COUNTY_CD.value,nvalue.county))
            natural_value.append(TreeElement(Tags.DISTRICT_CD.value,nvalue.district))
            natural_value.append(TreeElement(Tags.MUNICIPALITY_CD.value,nvalue.municipality))
            natural_value.append(TreeElement(Tags.COMMUNITY_CD.value,nvalue.community))
            natural_value.append(TreeElementOptional.create(Tags.ENV_COUNT.value,nvalue.env_count))
            natural_value.append(TreeElement(Tags.NATURAL_VALUE_CD.value,nvalue.natural_value_cd))
            natural_value.append(TreeElementOptional.create(Tags.TOTAL_AREA.value,nvalue.total_area))
            natural_value.append(TreeElementOptional.create(Tags.PUL_AREA.value,nvalue.pul_area))
            natural_value.append(TreeElementOptional.create(Tags.FOREST_AREA.value,nvalue.forest_area))
            natural_value.append(TreeElementOptional.create(Tags.FOREST_AREA_P.value,nvalue.forest_area_p))
            natural_value.append(TreeElementOptional.create(Tags.NFOREST_AREA_P.value,nvalue.nforest_area_p))
            natural_value.append(TreeElementOptional.create(Tags.NFOREST_AREA.value,nvalue.nforest_area))
            natural_values_xml.append(natural_value)
        return natural_values_xml