{%- macro paramvalue(param) -%}{%if param.input_type in ["select", "multiselect"]%}self.get_select_param(kwargs.get("{{param.name}}")){%
elif param.input_type in ["textarea"]%}self.get_textarea_param(kwargs.get("{{param.name}}")){%
else %}kwargs.get("{{param.name}}"){%endif%}{%- endmacro -%}
{%- macro paramcomment(param) -%}{{param.input_type}}{%if param.input_type in ["select", "multiselect"]%}, values: "{{param["values"]|list|map(attribute="label")|join('", "')}}"{%endif%}{%- endmacro -%}
# -*- coding: utf-8 -*-
# pragma pylint: disable=unused-argument, no-self-use
"""Function implementation"""

import logging
from resilient_circuits import ResilientComponent, function, StatusMessage, FunctionResult, FunctionError


class FunctionComponent(ResilientComponent):
    """Component that implements Resilient function(s)"""
{%for function_name in functions.keys()%}{%set function_def=functions[function_name]%}
    @function("{{function_name|js}}")
    def _{{function_name}}_function(self, event, *args, **kwargs):
        """Function: {{function_def.description.content}}"""
        try:
            # Get the wf_instance_id of the workflow this Function was called in
            wf_instance_id = event.message["workflow_instance"]["workflow_instance_id"]

            # Get the function parameters:{%for p in function_def.view_items%}{%set pdef=function_params[p.content] %}
            {{pdef.name}} = {{paramvalue(pdef)}}  # {{paramcomment(pdef)}}{%endfor%}

            log = logging.getLogger(__name__){%for p in function_def.view_items if not 'pass' in p.content|lower%}{%set pdef=function_params[p.content] %}
            log.info("{{pdef.text}}: %s", {{pdef.name}}){%endfor%}

            # PUT YOUR FUNCTION IMPLEMENTATION CODE HERE
            #  yield StatusMessage("starting...")
            #  yield StatusMessage("done...")

            results = {
                "value": "xyz"
            }

            # Produce a FunctionResult with the results
            yield FunctionResult(results)
        except Exception:
            yield FunctionError()
{%endfor%}
