{%- 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, handler, StatusMessage, FunctionResult, FunctionError


class FunctionComponent(ResilientComponent):
    """Component that implements Resilient function '{{loopvar}}"""

    def __init__(self, opts):
        """constructor provides access to the configuration options"""
        super(FunctionComponent, self).__init__(opts)
        self.options = opts.get("{{package}}", {})

    @handler("reload")
    def _reload(self, event, opts):
        """Configuration options have changed, save new values"""
        self.options = opts.get("{{package}}", {})

    @function("{{loopvar|js}}")
    def _{{loopvar}}_function(self, event, *args, **kwargs):
        """Function: {{functions[loopvar].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 functions[loopvar].view_items%}{%set pdef=function_params[p.content] %}
            {{pdef.name}} = {{paramvalue(pdef)}}  # {{paramcomment(pdef)}}{%endfor%}

            log = logging.getLogger(__name__){%for p in functions[loopvar].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()
