"""
from_scopings
=============
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 from_scopings(Operator):
    """Extracts multiple meshed region base on a scoping and saved in a
    MeshesContainer

    Parameters
    ----------
    scopings_container : ScopingsContainer
        If nodal scoping, then the scoping is
        transposed respecting the inclusive
        pin
    inclusive : int, optional
        If inclusive == 1 then all the elements/faces
        adjacent to the nodes ids in input
        are added, if inclusive == 0, only
        the elements/faces which have all
        their nodes in the scoping are
        included
    nodes_only : bool, optional
        Returns mesh with nodes only (without any
        elements). default is false.
    mesh : MeshedRegion


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

    >>> # Instantiate operator
    >>> op = dpf.operators.mesh.from_scopings()

    >>> # Make input connections
    >>> my_scopings_container = dpf.ScopingsContainer()
    >>> op.inputs.scopings_container.connect(my_scopings_container)
    >>> my_inclusive = int()
    >>> op.inputs.inclusive.connect(my_inclusive)
    >>> my_nodes_only = bool()
    >>> op.inputs.nodes_only.connect(my_nodes_only)
    >>> my_mesh = dpf.MeshedRegion()
    >>> op.inputs.mesh.connect(my_mesh)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.mesh.from_scopings(
    ...     scopings_container=my_scopings_container,
    ...     inclusive=my_inclusive,
    ...     nodes_only=my_nodes_only,
    ...     mesh=my_mesh,
    ... )

    >>> # Get output data
    >>> result_meshes = op.outputs.meshes()
    """

    def __init__(
        self,
        scopings_container=None,
        inclusive=None,
        nodes_only=None,
        mesh=None,
        config=None,
        server=None,
    ):
        super().__init__(name="meshes::by_scopings", config=config, server=server)
        self._inputs = InputsFromScopings(self)
        self._outputs = OutputsFromScopings(self)
        if scopings_container is not None:
            self.inputs.scopings_container.connect(scopings_container)
        if inclusive is not None:
            self.inputs.inclusive.connect(inclusive)
        if nodes_only is not None:
            self.inputs.nodes_only.connect(nodes_only)
        if mesh is not None:
            self.inputs.mesh.connect(mesh)

    @staticmethod
    def _spec():
        description = """Extracts multiple meshed region base on a scoping and saved in a
            MeshesContainer"""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                1: PinSpecification(
                    name="scopings_container",
                    type_names=["scopings_container"],
                    optional=False,
                    document="""If nodal scoping, then the scoping is
        transposed respecting the inclusive
        pin""",
                ),
                2: PinSpecification(
                    name="inclusive",
                    type_names=["int32"],
                    optional=True,
                    document="""If inclusive == 1 then all the elements/faces
        adjacent to the nodes ids in input
        are added, if inclusive == 0, only
        the elements/faces which have all
        their nodes in the scoping are
        included""",
                ),
                3: PinSpecification(
                    name="nodes_only",
                    type_names=["bool"],
                    optional=True,
                    document="""Returns mesh with nodes only (without any
        elements). default is false.""",
                ),
                7: PinSpecification(
                    name="mesh",
                    type_names=["abstract_meshed_region"],
                    optional=False,
                    document="""""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="meshes",
                    type_names=["meshes_container"],
                    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="meshes::by_scopings", server=server)

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

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

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

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


class InputsFromScopings(_Inputs):
    """Intermediate class used to connect user inputs to
    from_scopings operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.mesh.from_scopings()
    >>> my_scopings_container = dpf.ScopingsContainer()
    >>> op.inputs.scopings_container.connect(my_scopings_container)
    >>> my_inclusive = int()
    >>> op.inputs.inclusive.connect(my_inclusive)
    >>> my_nodes_only = bool()
    >>> op.inputs.nodes_only.connect(my_nodes_only)
    >>> my_mesh = dpf.MeshedRegion()
    >>> op.inputs.mesh.connect(my_mesh)
    """

    def __init__(self, op: Operator):
        super().__init__(from_scopings._spec().inputs, op)
        self._scopings_container = Input(from_scopings._spec().input_pin(1), 1, op, -1)
        self._inputs.append(self._scopings_container)
        self._inclusive = Input(from_scopings._spec().input_pin(2), 2, op, -1)
        self._inputs.append(self._inclusive)
        self._nodes_only = Input(from_scopings._spec().input_pin(3), 3, op, -1)
        self._inputs.append(self._nodes_only)
        self._mesh = Input(from_scopings._spec().input_pin(7), 7, op, -1)
        self._inputs.append(self._mesh)

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

        If nodal scoping, then the scoping is
        transposed respecting the inclusive
        pin

        Parameters
        ----------
        my_scopings_container : ScopingsContainer

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.from_scopings()
        >>> op.inputs.scopings_container.connect(my_scopings_container)
        >>> # or
        >>> op.inputs.scopings_container(my_scopings_container)
        """
        return self._scopings_container

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

        If inclusive == 1 then all the elements/faces
        adjacent to the nodes ids in input
        are added, if inclusive == 0, only
        the elements/faces which have all
        their nodes in the scoping are
        included

        Parameters
        ----------
        my_inclusive : int

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.from_scopings()
        >>> op.inputs.inclusive.connect(my_inclusive)
        >>> # or
        >>> op.inputs.inclusive(my_inclusive)
        """
        return self._inclusive

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

        Returns mesh with nodes only (without any
        elements). default is false.

        Parameters
        ----------
        my_nodes_only : bool

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.from_scopings()
        >>> op.inputs.nodes_only.connect(my_nodes_only)
        >>> # or
        >>> op.inputs.nodes_only(my_nodes_only)
        """
        return self._nodes_only

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

        Parameters
        ----------
        my_mesh : MeshedRegion

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.from_scopings()
        >>> op.inputs.mesh.connect(my_mesh)
        >>> # or
        >>> op.inputs.mesh(my_mesh)
        """
        return self._mesh


class OutputsFromScopings(_Outputs):
    """Intermediate class used to get outputs from
    from_scopings operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.mesh.from_scopings()
    >>> # Connect inputs : op.inputs. ...
    >>> result_meshes = op.outputs.meshes()
    """

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

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

        Returns
        ----------
        my_meshes : MeshesContainer

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.from_scopings()
        >>> # Connect inputs : op.inputs. ...
        >>> result_meshes = op.outputs.meshes()
        """  # noqa: E501
        return self._meshes
