"""
mesh_to_pyvista
===============
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 mesh_to_pyvista(Operator):
    """Export a MeshedRegion in the pyVista format.

    Parameters
    ----------
    coordinates : Field, optional
        Node coordinates. if not set, the node
        coordinates of the mesh are employed.
    as_linear : bool, optional
        Export a linear version of the mesh
        (quadratic surface elements do no
        include midside nodes). if not set,
        defaults to true.
    mesh : MeshedRegion
        Mesh to export in pyvista format
    vtk_updated : bool, optional
        True if the vtk version employed by pyvista
        is > vtk 9. default true.
    as_poly : bool, optional
        Export elements as polyhedrons (cell-face-
        node representation). default false.


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

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

    >>> # Make input connections
    >>> my_coordinates = dpf.Field()
    >>> op.inputs.coordinates.connect(my_coordinates)
    >>> my_as_linear = bool()
    >>> op.inputs.as_linear.connect(my_as_linear)
    >>> my_mesh = dpf.MeshedRegion()
    >>> op.inputs.mesh.connect(my_mesh)
    >>> my_vtk_updated = bool()
    >>> op.inputs.vtk_updated.connect(my_vtk_updated)
    >>> my_as_poly = bool()
    >>> op.inputs.as_poly.connect(my_as_poly)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.mesh.mesh_to_pyvista(
    ...     coordinates=my_coordinates,
    ...     as_linear=my_as_linear,
    ...     mesh=my_mesh,
    ...     vtk_updated=my_vtk_updated,
    ...     as_poly=my_as_poly,
    ... )

    >>> # Get output data
    >>> result_nodes = op.outputs.nodes()
    >>> result_cells = op.outputs.cells()
    >>> result_cell_types = op.outputs.cell_types()
    >>> result_offsets = op.outputs.offsets()
    """

    def __init__(
        self,
        coordinates=None,
        as_linear=None,
        mesh=None,
        vtk_updated=None,
        as_poly=None,
        config=None,
        server=None,
    ):
        super().__init__(name="mesh_to_pyvista", config=config, server=server)
        self._inputs = InputsMeshToPyvista(self)
        self._outputs = OutputsMeshToPyvista(self)
        if coordinates is not None:
            self.inputs.coordinates.connect(coordinates)
        if as_linear is not None:
            self.inputs.as_linear.connect(as_linear)
        if mesh is not None:
            self.inputs.mesh.connect(mesh)
        if vtk_updated is not None:
            self.inputs.vtk_updated.connect(vtk_updated)
        if as_poly is not None:
            self.inputs.as_poly.connect(as_poly)

    @staticmethod
    def _spec():
        description = """Export a MeshedRegion in the pyVista format."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                2: PinSpecification(
                    name="coordinates",
                    type_names=["field"],
                    optional=True,
                    document="""Node coordinates. if not set, the node
        coordinates of the mesh are employed.""",
                ),
                6: PinSpecification(
                    name="as_linear",
                    type_names=["bool"],
                    optional=True,
                    document="""Export a linear version of the mesh
        (quadratic surface elements do no
        include midside nodes). if not set,
        defaults to true.""",
                ),
                7: PinSpecification(
                    name="mesh",
                    type_names=["abstract_meshed_region"],
                    optional=False,
                    document="""Mesh to export in pyvista format""",
                ),
                60: PinSpecification(
                    name="vtk_updated",
                    type_names=["bool"],
                    optional=True,
                    document="""True if the vtk version employed by pyvista
        is > vtk 9. default true.""",
                ),
                200: PinSpecification(
                    name="as_poly",
                    type_names=["bool"],
                    optional=True,
                    document="""Export elements as polyhedrons (cell-face-
        node representation). default false.""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="nodes",
                    type_names=["field"],
                    optional=False,
                    document="""Node coordinates double vector""",
                ),
                1: PinSpecification(
                    name="cells",
                    type_names=["vector<int32>"],
                    optional=False,
                    document="""Cell connectivity int vector""",
                ),
                2: PinSpecification(
                    name="cell_types",
                    type_names=["vector<int32>"],
                    optional=False,
                    document="""Cell types property int vector""",
                ),
                3: PinSpecification(
                    name="offsets",
                    type_names=["vector<int32>"],
                    optional=True,
                    document="""If vtk_updated=false, offsets int vector""",
                ),
            },
        )
        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="mesh_to_pyvista", server=server)

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

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

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

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


class InputsMeshToPyvista(_Inputs):
    """Intermediate class used to connect user inputs to
    mesh_to_pyvista operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.mesh.mesh_to_pyvista()
    >>> my_coordinates = dpf.Field()
    >>> op.inputs.coordinates.connect(my_coordinates)
    >>> my_as_linear = bool()
    >>> op.inputs.as_linear.connect(my_as_linear)
    >>> my_mesh = dpf.MeshedRegion()
    >>> op.inputs.mesh.connect(my_mesh)
    >>> my_vtk_updated = bool()
    >>> op.inputs.vtk_updated.connect(my_vtk_updated)
    >>> my_as_poly = bool()
    >>> op.inputs.as_poly.connect(my_as_poly)
    """

    def __init__(self, op: Operator):
        super().__init__(mesh_to_pyvista._spec().inputs, op)
        self._coordinates = Input(mesh_to_pyvista._spec().input_pin(2), 2, op, -1)
        self._inputs.append(self._coordinates)
        self._as_linear = Input(mesh_to_pyvista._spec().input_pin(6), 6, op, -1)
        self._inputs.append(self._as_linear)
        self._mesh = Input(mesh_to_pyvista._spec().input_pin(7), 7, op, -1)
        self._inputs.append(self._mesh)
        self._vtk_updated = Input(mesh_to_pyvista._spec().input_pin(60), 60, op, -1)
        self._inputs.append(self._vtk_updated)
        self._as_poly = Input(mesh_to_pyvista._spec().input_pin(200), 200, op, -1)
        self._inputs.append(self._as_poly)

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

        Node coordinates. if not set, the node
        coordinates of the mesh are employed.

        Parameters
        ----------
        my_coordinates : Field

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> op.inputs.coordinates.connect(my_coordinates)
        >>> # or
        >>> op.inputs.coordinates(my_coordinates)
        """
        return self._coordinates

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

        Export a linear version of the mesh
        (quadratic surface elements do no
        include midside nodes). if not set,
        defaults to true.

        Parameters
        ----------
        my_as_linear : bool

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> op.inputs.as_linear.connect(my_as_linear)
        >>> # or
        >>> op.inputs.as_linear(my_as_linear)
        """
        return self._as_linear

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

        Mesh to export in pyvista format

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

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

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

        True if the vtk version employed by pyvista
        is > vtk 9. default true.

        Parameters
        ----------
        my_vtk_updated : bool

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> op.inputs.vtk_updated.connect(my_vtk_updated)
        >>> # or
        >>> op.inputs.vtk_updated(my_vtk_updated)
        """
        return self._vtk_updated

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

        Export elements as polyhedrons (cell-face-
        node representation). default false.

        Parameters
        ----------
        my_as_poly : bool

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> op.inputs.as_poly.connect(my_as_poly)
        >>> # or
        >>> op.inputs.as_poly(my_as_poly)
        """
        return self._as_poly


class OutputsMeshToPyvista(_Outputs):
    """Intermediate class used to get outputs from
    mesh_to_pyvista operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.mesh.mesh_to_pyvista()
    >>> # Connect inputs : op.inputs. ...
    >>> result_nodes = op.outputs.nodes()
    >>> result_cells = op.outputs.cells()
    >>> result_cell_types = op.outputs.cell_types()
    >>> result_offsets = op.outputs.offsets()
    """

    def __init__(self, op: Operator):
        super().__init__(mesh_to_pyvista._spec().outputs, op)
        self._nodes = Output(mesh_to_pyvista._spec().output_pin(0), 0, op)
        self._outputs.append(self._nodes)
        self._cells = Output(mesh_to_pyvista._spec().output_pin(1), 1, op)
        self._outputs.append(self._cells)
        self._cell_types = Output(mesh_to_pyvista._spec().output_pin(2), 2, op)
        self._outputs.append(self._cell_types)
        self._offsets = Output(mesh_to_pyvista._spec().output_pin(3), 3, op)
        self._outputs.append(self._offsets)

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

        Returns
        ----------
        my_nodes : Field

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> # Connect inputs : op.inputs. ...
        >>> result_nodes = op.outputs.nodes()
        """  # noqa: E501
        return self._nodes

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

        Returns
        ----------
        my_cells :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> # Connect inputs : op.inputs. ...
        >>> result_cells = op.outputs.cells()
        """  # noqa: E501
        return self._cells

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

        Returns
        ----------
        my_cell_types :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> # Connect inputs : op.inputs. ...
        >>> result_cell_types = op.outputs.cell_types()
        """  # noqa: E501
        return self._cell_types

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

        Returns
        ----------
        my_offsets :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.mesh.mesh_to_pyvista()
        >>> # Connect inputs : op.inputs. ...
        >>> result_offsets = op.outputs.offsets()
        """  # noqa: E501
        return self._offsets
