"""
merge_data_tree
===============
Autogenerated DPF operator classes.
"""
from warnings import warn
from ansys.dpf.core.dpf_operator import Operator
from ansys.dpf.core.inputs import Input, _Inputs
from ansys.dpf.core.outputs import Output, _Outputs
from ansys.dpf.core.operators.specification import PinSpecification, Specification


class merge_data_tree(Operator):
    """Merges a list of data trees. Attributes names shouldn't be shared
    accross data tree instances.

    Parameters
    ----------
    data_tree1 : DataTree
        Either a vector of data trees or data trees
        from pin 0 to ... to merge.
    data_tree2 : DataTree
        Either a vector of data trees or data trees
        from pin 0 to ... to merge.


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

    >>> # Instantiate operator
    >>> op = dpf.operators.utility.merge_data_tree()

    >>> # Make input connections
    >>> my_data_tree1 = dpf.DataTree()
    >>> op.inputs.data_tree1.connect(my_data_tree1)
    >>> my_data_tree2 = dpf.DataTree()
    >>> op.inputs.data_tree2.connect(my_data_tree2)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.utility.merge_data_tree(
    ...     data_tree1=my_data_tree1,
    ...     data_tree2=my_data_tree2,
    ... )

    >>> # Get output data
    >>> result_any = op.outputs.any()
    """

    def __init__(self, data_tree1=None, data_tree2=None, config=None, server=None):
        super().__init__(name="merge::data_tree", config=config, server=server)
        self._inputs = InputsMergeDataTree(self)
        self._outputs = OutputsMergeDataTree(self)
        if data_tree1 is not None:
            self.inputs.data_tree1.connect(data_tree1)
        if data_tree2 is not None:
            self.inputs.data_tree2.connect(data_tree2)

    @staticmethod
    def _spec():
        description = """Merges a list of data trees. Attributes names shouldn't be shared
            accross data tree instances."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="data_tree",
                    type_names=["data_tree"],
                    optional=False,
                    document="""Either a vector of data trees or data trees
        from pin 0 to ... to merge.""",
                ),
                1: PinSpecification(
                    name="data_tree",
                    type_names=["data_tree"],
                    optional=False,
                    document="""Either a vector of data trees or data trees
        from pin 0 to ... to merge.""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="any",
                    type_names=["any"],
                    optional=False,
                    document="""""",
                ),
            },
        )
        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="merge::data_tree", server=server)

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

        Returns
        --------
        inputs : InputsMergeDataTree
        """
        return super().inputs

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

        Returns
        --------
        outputs : OutputsMergeDataTree
        """
        return super().outputs


class InputsMergeDataTree(_Inputs):
    """Intermediate class used to connect user inputs to
    merge_data_tree operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.merge_data_tree()
    >>> my_data_tree1 = dpf.DataTree()
    >>> op.inputs.data_tree1.connect(my_data_tree1)
    >>> my_data_tree2 = dpf.DataTree()
    >>> op.inputs.data_tree2.connect(my_data_tree2)
    """

    def __init__(self, op: Operator):
        super().__init__(merge_data_tree._spec().inputs, op)
        self._data_tree1 = Input(merge_data_tree._spec().input_pin(0), 0, op, 0)
        self._inputs.append(self._data_tree1)
        self._data_tree2 = Input(merge_data_tree._spec().input_pin(1), 1, op, 1)
        self._inputs.append(self._data_tree2)

    @property
    def data_tree1(self):
        """Allows to connect data_tree1 input to the operator.

        Either a vector of data trees or data trees
        from pin 0 to ... to merge.

        Parameters
        ----------
        my_data_tree1 : DataTree

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.merge_data_tree()
        >>> op.inputs.data_tree1.connect(my_data_tree1)
        >>> # or
        >>> op.inputs.data_tree1(my_data_tree1)
        """
        return self._data_tree1

    @property
    def data_tree2(self):
        """Allows to connect data_tree2 input to the operator.

        Either a vector of data trees or data trees
        from pin 0 to ... to merge.

        Parameters
        ----------
        my_data_tree2 : DataTree

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.merge_data_tree()
        >>> op.inputs.data_tree2.connect(my_data_tree2)
        >>> # or
        >>> op.inputs.data_tree2(my_data_tree2)
        """
        return self._data_tree2


class OutputsMergeDataTree(_Outputs):
    """Intermediate class used to get outputs from
    merge_data_tree operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.merge_data_tree()
    >>> # Connect inputs : op.inputs. ...
    >>> result_any = op.outputs.any()
    """

    def __init__(self, op: Operator):
        super().__init__(merge_data_tree._spec().outputs, op)
        self._any = Output(merge_data_tree._spec().output_pin(0), 0, op)
        self._outputs.append(self._any)

    @property
    def any(self):
        """Allows to get any output of the operator

        Returns
        ----------
        my_any : Any

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.merge_data_tree()
        >>> # Connect inputs : op.inputs. ...
        >>> result_any = op.outputs.any()
        """  # noqa: E501
        return self._any
