{%- macro get_type_hint(_fields, use_base_type) -%}
{%- if _fields -%}
{#There will only ever be a single field for RootModel#}
{%- if use_base_type -%}
{{- _fields[0].base_type_hint}}
{%- else -%}
{{- _fields[0].type_hint}}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}


{% for decorator in decorators -%}
{{ decorator }}
{% endfor -%}

{#- Use base_type_hint in generic when regex_engine is set to avoid evaluating pattern before config is processed -#}
{%- set use_base_type = config and config.regex_engine -%}
class {{ class_name }}({%- if schema_runtime_validation_use_base -%}{{ schema_runtime_validation_base_class_name }}, {% endif -%}{{ base_class }}{%- if fields -%}[{{get_type_hint(fields, use_base_type)}}]{%- endif -%}{%- if sequence_base_class is defined -%}, {{ sequence_base_class }}{%- endif -%}):{% if comment is defined %}  # {{ comment }}{% endif %}
{%- if description %}
    {{ description }}
{%- endif %}
{%- if config %}
{%- filter indent(4) %}
{% include 'ConfigDict.jinja2' %}
{%- endfilter %}
{%- endif %}
{%- for line in class_body_lines %}
    {{ line }}
{%- endfor %}
{%- include 'schema_runtime_validation.jinja2' %}
{%- if not fields %}
{%- if not description and not config and not class_body_lines and not schema_runtime_validation %}
    pass
{%- endif %}
{%- else %}
    {%- set field = fields[0] %}
    {%- if not field.annotated and field.field %}
    root: {{ field.type_hint }} = {{ field.field }}
    {%- else %}
    {%- if field.annotated %}
    root: {{ field.annotated }}
    {%- else %}
    root: {{ field.type_hint }}
    {%- endif %}
    {%- if not field.has_default_factory_in_field and not (field.required or (field.represented_default == 'None' and field.strip_default_none))
            %} = {{ field.represented_default }}
    {%- endif -%}
    {%- endif %}
    {%- if field.docstring %}
    {{ field.docstring }}
    {%- elif field.inline_field_docstring %}
    {{ field.inline_field_docstring }}

    {%- endif %}
{%- if sequence_item_type is defined and sequence_slice_type is defined %}

    def __iter__(self) -> Iterator[{{ sequence_item_type }}]:
        return iter(self.root)

    @overload
    def __getitem__(self, index: SupportsIndex) -> {{ sequence_item_type }}:
        pass

    @overload
    def __getitem__(self, index: slice) -> {{ sequence_slice_type }}:
        pass

    def __getitem__(self, index: SupportsIndex | slice) -> {{ sequence_item_type }} | {{ sequence_slice_type }}:
        return self.root[index]

    def __len__(self) -> int:
        return len(self.root)
{%- endif %}
{%- for method in methods %}

    {{ method }}
{%- endfor %}
{%- endif %}
