{#
    This is a custom template derived from:
    https://github.com/openapi-generators/openapi-python-client/blob/v.0.10.7/openapi_python_client/templates/property_templates/list_property.py.jinja
#}
{% macro construct(property, source, initial_value="[]") %}
{% set inner_property = property.inner_property %}
{% if inner_property.template %}
{% set inner_source = inner_property.python_name + "_data" %}
{{ property.python_name }} = {{ initial_value }}
_{{ property.python_name }} = {{ source }}
if _{{ property.python_name }} is UNSET:
    {{ property.python_name }} = UNSET
else:
    for {{ inner_source }} in (_{{ property.python_name }} or []):
        {% from "property_templates/" + inner_property.template import construct %}
        {{ construct(inner_property, inner_source) | indent(8) }}
        {{ property.python_name }}.append({{ inner_property.python_name }})
{% else %}
{{ property.python_name }} = cast({{ property.get_type_string(no_optional=True) }}, {{ source }})
{% endif %}
{% endmacro %}

{% macro _transform(property, source, destination, stringify, transform_method) %}
{% set inner_property = property.inner_property %}
{% if stringify %}
{% set stringified_destination = destination %}
{% set destination = "_temp_" + destination %}
{% endif %}
{% if inner_property.template %}
{% set inner_source = inner_property.python_name + "_data" %}
{{ destination }} = []
for {{ inner_source }} in {{ source }}:
    {% from "property_templates/" + inner_property.template import transform %}
    {{ transform(inner_property, inner_source, inner_property.python_name, transform_method) | indent(4) }}
    {{ destination }}.append({{ inner_property.python_name }})
{% else %}
{{ destination }} = {{ source }}
{% endif %}
{% if stringify %}
{{ stringified_destination }} = (None, json.dumps({{ destination }}), 'application/json')
{% endif %}
{% endmacro %}

{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, list){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, stringify=False, transform_method="to_dict") %}
{% set inner_property = property.inner_property %}
{% if stringify %}
    {% set type_string = "Union[Unset, Tuple[None, str, str]]" %}
{% else %}
    {% set type_string = property.get_type_string(json=True) %}
{% endif %}
{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET
if not isinstance({{ source }}, Unset):
{% if property.nullable %}
    if {{ source }} is None:
        {{ destination }} = None
    else:
        {{ _transform(property, source, destination, stringify, transform_method) | indent(8)}}
{% else %}
    {{ _transform(property, source, destination, stringify, transform_method) | indent(4)}}
{% endif %}
{% endmacro %}

{% macro transform_multipart(property, source, destination) %}
{{ transform(property, source, destination, transform_method="to_multipart") }}
{% endmacro %}
