{% macro construct_function(property, source) %}
{{ property.class_info.name }}({{ 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 }}, {{ property.value_type.__name__ }}){% endmacro %}

{% macro transform(property, source, destination, declare_type=True, multipart=False) %}
{% set transformed = source + ".value" %}
{% set type_string = property.get_type_string(json=True) %}
{% if multipart %}
    {% set transformed = "(None, str(" + transformed + ").encode(), \"text/plain\")" %}
    {% set type_string = "Union[Unset, Tuple[None, bytes, str]]" %}
{% endif %}
{% if property.required %}
{% if property.nullable %}
{{ destination }} = {{ transformed }} if {{ source }} else None
{% else %}
{{ destination }} = {{ transformed }}
{% endif %}
{% else %}
{{ 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 %}
{% endif %}
{% endmacro %}

{% macro transform_header(property, source, destination) %}
{{ destination }} = str({{ source }})
{% endmacro %}
