{# Custom dataclass template for OpenTelemetry configuration models.
   Extends the default datamodel-codegen dataclass template to support
   JSON Schema additionalProperties. When a schema type allows additional
   properties (e.g. Sampler, SpanExporter), this template adds:
   - @_additional_properties decorator (captures user-defined kwargs)
   - additional_properties: ClassVar[dict[str, Any]] annotation (for type checkers)

   The template checks two context variables set by datamodel-codegen:
   - additionalProperties: set when the schema value is a boolean (true/false)
   - additionalPropertiesType: set when the schema value is a type object
     (e.g. {"type": ["object", "null"]}), which is how the OTel config
     schema defines it for plugin-capable types.

   See TestGeneratedModelsHaveAdditionalProperties in test_common.py for
   regression tests that guard against changes in these context variables.
-#}
{% for decorator in decorators -%}
{{ decorator }}
{% endfor -%}
{%- set args = [] %}
{%- for k, v in (dataclass_arguments or {}).items() %}
    {%- if v is not none and v is not false %}
        {%- set _ = args.append(k ~ '=' ~ (v|pprint)) %}
    {%- endif %}
{%- endfor %}
{%- set has_additional = (additionalProperties is defined and additionalProperties != false) or (additionalPropertiesType is defined) %}
{%- if has_additional %}
@_additional_properties
{%- endif %}
{%- if args %}
@dataclass({{ args | join(', ') }})
{%- else %}
@dataclass
{%- endif %}
{%- if base_class %}
class {{ class_name }}({{ base_class }}):
{%- else %}
class {{ class_name }}:
{%- endif %}
{%- if description %}
    """
    {{ description | escape_docstring | indent(4) }}
    """
{%- endif %}
{%- if not fields and not description and not has_additional %}
    pass
{%- endif %}
{%- for field in fields -%}
    {%- if field.field %}
    {{ field.name }}: {{ field.type_hint }} = {{ field.field }}
    {%- else %}
    {{ field.name }}: {{ field.type_hint }}
    {%- if not (field.required or (field.represented_default == 'None' and field.strip_default_none))
            %} = {{ field.represented_default }}
    {%- endif -%}
    {%- endif %}
    {%- if field.docstring %}
    """
    {{ field.docstring | escape_docstring | indent(4) }}
    """
{%- if field.use_inline_field_description and not loop.last %}

{% endif %}
    {%- elif field.inline_field_docstring %}
    {{ field.inline_field_docstring }}
{%- if not loop.last %}

{% endif %}
    {%- endif %}
{%- endfor -%}
{%- if has_additional %}
    additional_properties: ClassVar[dict[str, Any]]
{%- endif -%}
