"""
THIS IS PYTHON CODE GENERATED BY pyvenus/resources.py! 
DO NOT EDIT THIS FILE DIRECTLY!
"""

from pyvenus import Connection, Variable, Array, Sequence, Device, Liquidclass
from typing import Union

{% for smt in submethods %}
class {{ smt.name[0]|upper}}{{smt.name[1:]|lower }}:
    def __init__(self, con: Connection):
        self.__con = con
        self.__con.execute(definitions=r'#include "{{ smt.file }}"')

    {% for f in smt.functions -%}
    def {{ f.name }}(self
        {%- for p in f.parameters -%}
            {% if p.pass_mode == "value" -%}
                , {{ p.name }}
                {%- if p.default_value is not none -%}
                    ={{ p.default_value }}
                {%- endif -%}
            {%- else -%}
                , {{ p.name }}: {{ p.py_type }}
            {%- endif -%}
        {% endfor -%}):
        r"""Python function generated from submethod '{{ f.name }}' in '{{ smt.name }}.smt'

        {{ f.comment }}

        Args:
        {%- for p in f.parameters %}
            {{ p.name }} ({{ p.py_type }}{% if p.default_value is not none %}, optional{% endif %}) ({{ p. direction }}): {{ p.comment }}
        {%- endfor %}
        """

        # push all variables that are passed into the submethod
        {% for p in f.parameters -%}
            {%- if p.pass_mode == "variable" and p.hsl_type != "device" -%}
                {{ p.name }}.push()
            {%- endif %}
        {% endfor %}

        # generate the parameter string for the HSL function call
        parameter_string = ""
        {%- for p in f.parameters %}
        {% if p.pass_mode == "value" -%}
        if isinstance({{ p.name }}, Variable):
            value = {{ p.name }}.value
        else:
            value = {{ p.name }}
        {%- endif %}
        parameter_string +=
        {%- if loop.index > 1 %} ", " +{% endif -%}
        {%- if p.pass_mode == "variable" %} {{ p.name }}.name{% endif %}
        {%- if p.pass_mode == "value" %} (f'"{value}"' if isinstance(value, str) or isinstance(value, Liquidclass) else str(value)){% endif %}
        {% endfor -%}

        # call the HSL function
        self.__con.execute("{{ smt.name|upper }}::{{ f.name }}(" + parameter_string + ");")

        # pull all variables there were returned by the submethod
        {%- for p in f.parameters %}
        {%- if p.pass_mode == "variable" and p.hsl_type != "device" and p.direction in ["out", "in_out"] %}
        {{ p.name }}.pull()
        {% endif -%}
        {% endfor %}
    {% endfor -%}

{% endfor %}
