{#
    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/model_property.py.jinja
#}
{% macro construct_function(property, source) %}
{{ property.class_info.name }}.from_dict({{ source }})
{% endmacro %}

{% from "property_templates/property_macros.py.jinja" import construct_template %}

{% macro construct(property, source, initial_value=None) %}
{{ construct_template(construct_function, property, source, initial_value=initial_value) }}
{% endmacro %}

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

{% macro transform(property, source, destination, declare_type=True, stringify=False, transform_method="to_dict") %}
{% set transformed = source + "." + transform_method + "()" %}
{% if stringify %}
    {% set transformed = "(None, json.dumps(" + transformed + "), 'application/json')" %}
    {% 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 %}
    {{ destination }} = {{ transformed }} if {{ source }} else None
{% else %}
    {{ destination }} = {{ transformed }}
{% endif %}
{% endmacro %}

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