{% set help = obj|class_docstring|trim -%}
{% set level = level|default(0)-%}
{% set namespace = obj.namespace or namespace|default(None) -%}
{% set class_name =  obj.name|class_name -%}
{% set parents = parents|default([obj.name]) %}

@dataclass
class {{ class_name }}{{"({})".format(obj.extensions|map(attribute='type')|map('type_name')|join(', ')) if obj.extensions }}:
{%- if help %}
{{ help|indent(4, first=True) }}
{%- endif -%}
{%- if parents|length == 1 and (class_name != obj.name or obj.namespace or obj.is_nillable) %}
    class Meta:
        {%- if class_name != obj.name %}
        name = "{{ obj.name }}"
        {%- endif -%}
        {%- if obj.is_nillable %}
        nillable = True
        {%- endif -%}
        {%- if obj.namespace %}
        namespace = "{{ obj.namespace }}"
        {%- endif %}
{% elif obj.attrs|length == 0 and not help %}
    pass
{%- endif -%}
{%- for attr in obj.attrs %}
    {%- set metadata = attr|attribute_metadata(namespace) %}
    {{ attr.name|attribute_name }}: {{ attr|attribute_type(parents) }} = field(
        {% if attr.fixed -%}
        init=False,
        {% endif -%}
        {{ "default_factory" if attr.is_factory else "default" }}={{ attr|attribute_default(obj.ns_map) }},
        {%- if metadata %}
        metadata=dict(
            {{ metadata|format_arguments|indent(12) }}
        )
        {%- endif %}
    )
{%- endfor -%}
{%- for inner in obj.inner %}
    {%- set tpl = "enum.jinja2" if inner.is_enumeration else "class.jinja2" -%}
    {%- filter indent(4) -%}
        {%- with obj=inner, namespace=obj.namespace or namespace, parents=parents + [inner.name] -%}
            {% include tpl %}
        {%- endwith -%}
    {%- endfilter -%}
{%- endfor -%}
