## Imports needed for compilation
<%
from fconfig import builder
from fconfig.config_data_object import ConfigDataObject
%>
## We need these imports only in a root config class
% if is_root:
import fconfig.configuration

from fconfig.config import Config


% endif
## Other config classes imports. The empty condition is necessary to prevent empty lines generated by mako.
% if array_properties:
    % for key, value in array_properties.items():
        % if isinstance(value[0], ConfigDataObject):
from ${value[1]} import ${builder.get_class_name(value[1])}
        % endif
    % endfor
    % if not object_properties:


    % endif
% endif
% if object_properties:
    % for key, value in object_properties.items():
        % if value[3]:
import ${value[0]}
        % endif
from ${value[0]} import ${value[1]}
    % endfor


% endif
## now newline here it is there already due to mako mishandeling of newlines
% if is_root:
class ${class_name}(Config):
% else:
class ${class_name}:
% endif

    def __init__(self, properties: dict = None):
        ## Basic properties
        % for key in properties:
        self.${key} = properties.get("${key}")
        % endfor
        ## Object properties. The empty condition is necessary to prevent empty lines generated by mako.
        % if object_properties:
            % for key, value in object_properties.items():
        self.${key} = ${value[1]}(properties.get("${key}"))
                % if value[3]:
        ${value[0]}.config = self.${key}
                % endif
            % endfor
        % endif
        ## Array properties
        % for key, value in array_properties.items():
            % if isinstance(value[0], ConfigDataObject):
        self.${key} = []
                % if value[0][0].is_array:
Error: Multi-dimensional arrays not supported yet
                % else:
                    <% item_class_name = builder.get_class_name(value[1]) %>
        for item in properties.get("${key}"):
            self.${key}.append(${item_class_name}(item))
                    % endif
            ## % if isinstance(value, ConfigDataObject) and not value.is_array:
            ##% if isinstance(value, ConfigDataObject):
            ##TEST
            % else:
        self.${key} = [array_member for array_member in properties.get("${key}")]
            % endif
        % endfor
        pass
## Config loading
% if is_root:


config: ${class_name} = fconfig.configuration.load(${parent_parameter_string})
% endif