{% set level = level|default(0) -%}
{% set help | format_docstring(level + 1) %}
    {%- include "docstrings." + docstring_name + ".jinja2" -%}
{% endset -%}
{% set parent_namespace = obj.namespace if obj.namespace is not none else parent_namespace|default(None) -%}
{% set parents = parents|default([obj.name]) -%}
{% set class_name =  obj.name|class_name -%}
{% set class_annotations =  obj | class_annotations(class_name) -%}
{% set global_type = level == 0 and not obj.local_type -%}
{% set local_name =  obj.meta_name or obj.name -%}
{% set local_name = None if class_name == local_name or not global_type else local_name -%}
{% set base_classes = obj | class_bases(class_name) | join(', ')-%}
{% set target_namespace = obj.target_namespace if global_type and module_namespace != obj.target_namespace else None %}

{{ class_annotations | join('\n') }}
class {{ class_name }}{{"({})".format(base_classes) if base_classes }}:
{%- if help %}
{{ help|indent(4, first=True) }}
{%- endif -%}
{%- if local_name or obj.is_nillable or obj.namespace is not none or target_namespace or obj.local_type %}
    class Meta:
        {%- if obj.local_type %}
        global_type = False
        {%- endif -%}
        {%- if local_name %}
        name = "{{ local_name }}"
        {%- endif -%}
        {%- if obj.is_nillable %}
        nillable = True
        {%- endif -%}
        {%- if obj.namespace is not none %}
        namespace = "{{ obj.namespace }}"
        {%- endif %}
        {%- if target_namespace and target_namespace != obj.namespace %}
        target_namespace = "{{ target_namespace }}"
        {%- endif %}
{% elif obj.attrs|length == 0 and not help %}
    pass
{%- endif -%}
{%- for attr in obj.attrs %}
    {%- set field_typing = attr|field_type(parents) %}
    {%- set field_definition = attr|field_definition(obj.ns_map, parent_namespace, parents) %}
    {{ attr.name|field_name(obj.name) }}: {{ field_typing }} = {{ field_definition }}
{%- endfor -%}
{%- for inner in obj.inner %}
    {%- set tpl = "enum.jinja2" if inner.is_enumeration else "class.jinja2" -%}
    {%- set inner_parents = parents + [inner.name] -%}
    {%- filter indent(4) -%}
        {%- with obj=inner, parents=inner_parents, level=(level + 1) -%}
            {% include tpl %}
        {%- endwith -%}
    {%- endfilter -%}
{%- endfor -%}
