{% 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) %}
{{ construct_template(construct_function, property, source) }}
{% 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 property.required %}
{{ destination }} = {{ transformed }}
{%- else %}
{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET
if not isinstance({{ source }}, Unset):
    {{ destination }} = {{ transformed }}
{% endif %}
{% endmacro %}

{% macro transform_multipart(property, source, destination) %}
{% set transformed = "(None, str(" + source + ".value" + ").encode(), \"text/plain\")" %}
{% set type_string = "Union[Unset, tuple[None, bytes, str]]" %}
{% if property.required %}
{{ destination }} = {{ transformed }}
{%- else %}
{{ destination }}: {{ type_string }} = UNSET
if not isinstance({{ source }}, Unset):
    {{ destination }} = {{ transformed }}
{% endif %}
{% endmacro %}

{% macro transform_header(source) %}
str({{ source }})
{% endmacro %}
