"""
{{class_name}}
{{class_name_underlining}}
Autogenerated DPF operator classes.
"""
from warnings import warn
from ansys.dpf.core.dpf_operator import Operator
from ansys.dpf.core.inputs import Input, _Inputs
{{#outputs}}
from ansys.dpf.core.outputs import Output, _Outputs
{{/outputs}}
{{^outputs}}
from ansys.dpf.core.outputs import _Outputs
{{/outputs}}
{{#multiple_output_types}}
from ansys.dpf.core.outputs import _modify_output_spec_with_one_type
{{/multiple_output_types}}
from ansys.dpf.core.operators.specification import PinSpecification, Specification

class {{class_name}}(Operator):
    """{{{docstring}}}

    Parameters
    ----------
    {{#input_pins}}
    {{#optional}}
    {{name}} :{{#types_for_docstring}} {{types_for_docstring}},{{/types_for_docstring}} optional
    {{/optional}}
    {{^optional}}
    {{name}} :{{#types_for_docstring}} {{types_for_docstring}}{{/types_for_docstring}}
    {{/optional}}
    {{#document}}
        {{{document}}}
    {{/document}}
    {{/input_pins}}


    Examples
    --------
    >>> from ansys.dpf import core as dpf

    >>> # Instantiate operator
    >>> op = dpf.operators.{{category}}.{{class_name}}()

    >>> # Make input connections
    {{#input_pins}}
    >>> my_{{name}} = {{^built_in_main_type}}dpf.{{/built_in_main_type}}{{main_type}}()
    >>> op.inputs.{{name}}.connect(my_{{name}})
    {{/input_pins}}

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.{{category}}.{{class_name}}(
    {{#input_pins}}
    ...     {{name}}=my_{{name}},
    {{/input_pins}}
    ... )

    {{#outputs}}
    >>> # Get output data
    {{#output_pins}}
    >>> result_{{name}} = op.outputs.{{name}}()
    {{/output_pins}}
    {{/outputs}}
    """

    def __init__(self, {{#input_pins}}{{name}}=None, {{/input_pins}}config=None, server=None):
        super().__init__(name="{{operator_name}}", config=config, server=server)
        self._inputs = Inputs{{capital_class_name}}(self)
        self._outputs = Outputs{{capital_class_name}}(self)
        {{#input_pins}}
        if {{name}} is not None:
            self.inputs.{{name}}.connect({{name}})
        {{/input_pins}}

    @staticmethod
    def _spec():
        description = """{{specification_description}}"""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                {{#input_pins}}
                {{id}}: PinSpecification(
                    name="{{pin_name}}",
                    {{#has_types}}
                    type_names={{{types}}},
                    {{/has_types}}
                    {{^has_types}}
                    type_names=["any"],
                    {{/has_types}}
                    optional={{optional}},
                    document="""{{{document}}}""",
                    {{#has_derived_class}}
                    name_derived_class=["{{{derived_type_name}}}"],
                    {{/has_derived_class}}
                ),
                {{/input_pins}}
            },
            map_output_pin_spec={
                {{#output_pins}}
                {{id}}: PinSpecification(
                    name="{{name}}",
                    {{#has_types}}
                    type_names={{{types}}},
                    {{/has_types}}
                    optional={{optional}},
                    document="""{{{document}}}""",
                    {{#has_derived_class}}
                    name_derived_class=["{{{derived_type_name}}}"],
                    {{/has_derived_class}}
                ),
                {{/output_pins}}
            },
        )
        return spec

    @staticmethod
    def default_config(server=None):
        """Returns the default config of the operator.

        This config can then be changed to the user needs and be used to
        instantiate the operator. The Configuration allows to customize
        how the operation will be processed by the operator.

        Parameters
        ----------
        server : server.DPFServer, optional
            Server with channel connected to the remote or local instance. When
            ``None``, attempts to use the global server.
        """
        return Operator.default_config(name="{{operator_name}}", server=server)

    @property
    def inputs(self):
        """Enables to connect inputs to the operator

        Returns
        --------
        inputs : Inputs{{capital_class_name}}
        """
        return super().inputs

    @property
    def outputs(self):
        """Enables to get outputs of the operator by evaluating it

        Returns
        --------
        outputs : Outputs{{capital_class_name}}
        """
        return super().outputs

class Inputs{{capital_class_name}}(_Inputs):
    """Intermediate class used to connect user inputs to
    {{class_name}} operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.{{category}}.{{class_name}}()
    {{#input_pins}}
    >>> my_{{name}} = {{^built_in_main_type}}dpf.{{/built_in_main_type}}{{main_type}}()
    >>> op.inputs.{{name}}.connect(my_{{name}})
    {{/input_pins}}
    """

    def __init__(self, op: Operator):
        super().__init__({{class_name}}._spec().inputs, op)
        {{#input_pins}}
        self._{{name}} = Input({{class_name}}._spec().input_pin({{id}}), {{id}}, op, {{ellipsis}})
        self._inputs.append(self._{{name}})
        {{/input_pins}}

    {{#input_pins}}
    @property
    def {{name}}(self):
        """Allows to connect {{name}} input to the operator.
        {{#document}}

        {{{document}}}
        {{/document}}

        Parameters
        ----------
        my_{{name}} :{{#types_for_docstring}} {{types_for_docstring}}{{/types_for_docstring}}

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.{{category}}.{{class_name}}()
        >>> op.inputs.{{name}}.connect(my_{{name}})
        >>> # or
        >>> op.inputs.{{name}}(my_{{name}})
        """
        return self._{{name}}

    {{/input_pins}}
class Outputs{{capital_class_name}}(_Outputs):
    """Intermediate class used to get outputs from
    {{class_name}} operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.{{category}}.{{class_name}}()
    >>> # Connect inputs : op.inputs. ...
    {{#output_pins}}
    >>> result_{{name}} = op.outputs.{{name}}()
    {{/output_pins}}
    """

    def __init__(self, op: Operator):
        super().__init__({{class_name}}._spec().outputs, op)
        {{#output_pins}}
        {{#multiple_types}}
        {{#printable_type_names}}
        self.{{name}}_as_{{.}} = Output(_modify_output_spec_with_one_type({{class_name}}._spec().output_pin({{id}}), "{{.}}"), {{id}}, op) 
        self._outputs.append(self.{{name}}_as_{{.}})
        {{/printable_type_names}}
        {{/multiple_types}}
        {{^multiple_types}}
        self._{{name}} = Output({{class_name}}._spec().output_pin({{id}}), {{id}}, op)
        self._outputs.append(self._{{name}})
        {{/multiple_types}}
        {{/output_pins}}
    {{#output_pins}}{{^multiple_types}}

    @property
    def {{name}}(self):
        """Allows to get {{name}} output of the operator

        Returns
        ----------
        {{#derived_type_name}}
        my_{{name}} : {{derived_type_name}}
        {{/derived_type_name}}
        {{^derived_type_name}}
        my_{{name}} :{{#types_for_docstring}} {{types_for_docstring}}{{/types_for_docstring}}
        {{/derived_type_name}}

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.{{category}}.{{class_name}}()
        >>> # Connect inputs : op.inputs. ...
        >>> result_{{name}} = op.outputs.{{name}}()
        """ # noqa: E501
        return self._{{name}}
    {{/multiple_types}}{{/output_pins}}