"""
scalars_to_field
================
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 scalars_to_field(Operator):
    """Create scalar or vector Field.

    Parameters
    ----------
    double_or_vector_double : float, optional
        Data of the field, default is 0-field.
        specify a double to have a field of
        same value or specify directly the
        data vector.
    unit : str, optional
        Unit symbol (m, hz, kg, ...)
    location : str, optional
        Location of the field ex 'nodal',
        'elementalnodal', 'elemental'...
        default is 'numeric'.
    num_entity : int, optional
        Number of field entities. default is 1 or the
        size of the scoping in input if
        specified.
    num_comp : int, optional
        Number of field components. default is 1.
    scoping : Scoping, optional
        Scoping.


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

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

    >>> # Make input connections
    >>> my_double_or_vector_double = float()
    >>> op.inputs.double_or_vector_double.connect(my_double_or_vector_double)
    >>> my_unit = str()
    >>> op.inputs.unit.connect(my_unit)
    >>> my_location = str()
    >>> op.inputs.location.connect(my_location)
    >>> my_num_entity = int()
    >>> op.inputs.num_entity.connect(my_num_entity)
    >>> my_num_comp = int()
    >>> op.inputs.num_comp.connect(my_num_comp)
    >>> my_scoping = dpf.Scoping()
    >>> op.inputs.scoping.connect(my_scoping)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.utility.scalars_to_field(
    ...     double_or_vector_double=my_double_or_vector_double,
    ...     unit=my_unit,
    ...     location=my_location,
    ...     num_entity=my_num_entity,
    ...     num_comp=my_num_comp,
    ...     scoping=my_scoping,
    ... )

    >>> # Get output data
    >>> result_field = op.outputs.field()
    """

    def __init__(
        self,
        double_or_vector_double=None,
        unit=None,
        location=None,
        num_entity=None,
        num_comp=None,
        scoping=None,
        config=None,
        server=None,
    ):
        super().__init__(name="fieldify", config=config, server=server)
        self._inputs = InputsScalarsToField(self)
        self._outputs = OutputsScalarsToField(self)
        if double_or_vector_double is not None:
            self.inputs.double_or_vector_double.connect(double_or_vector_double)
        if unit is not None:
            self.inputs.unit.connect(unit)
        if location is not None:
            self.inputs.location.connect(location)
        if num_entity is not None:
            self.inputs.num_entity.connect(num_entity)
        if num_comp is not None:
            self.inputs.num_comp.connect(num_comp)
        if scoping is not None:
            self.inputs.scoping.connect(scoping)

    @staticmethod
    def _spec():
        description = """Create scalar or vector Field."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="double_or_vector_double",
                    type_names=["double", "vector<double>"],
                    optional=True,
                    document="""Data of the field, default is 0-field.
        specify a double to have a field of
        same value or specify directly the
        data vector.""",
                ),
                1: PinSpecification(
                    name="unit",
                    type_names=["string"],
                    optional=True,
                    document="""Unit symbol (m, hz, kg, ...)""",
                ),
                2: PinSpecification(
                    name="location",
                    type_names=["string"],
                    optional=True,
                    document="""Location of the field ex 'nodal',
        'elementalnodal', 'elemental'...
        default is 'numeric'.""",
                ),
                3: PinSpecification(
                    name="num_entity",
                    type_names=["int32"],
                    optional=True,
                    document="""Number of field entities. default is 1 or the
        size of the scoping in input if
        specified.""",
                ),
                4: PinSpecification(
                    name="num_comp",
                    type_names=["int32"],
                    optional=True,
                    document="""Number of field components. default is 1.""",
                ),
                5: PinSpecification(
                    name="scoping",
                    type_names=["scoping"],
                    optional=True,
                    document="""Scoping.""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="field",
                    type_names=["field"],
                    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="fieldify", server=server)

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

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

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

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


class InputsScalarsToField(_Inputs):
    """Intermediate class used to connect user inputs to
    scalars_to_field operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.scalars_to_field()
    >>> my_double_or_vector_double = float()
    >>> op.inputs.double_or_vector_double.connect(my_double_or_vector_double)
    >>> my_unit = str()
    >>> op.inputs.unit.connect(my_unit)
    >>> my_location = str()
    >>> op.inputs.location.connect(my_location)
    >>> my_num_entity = int()
    >>> op.inputs.num_entity.connect(my_num_entity)
    >>> my_num_comp = int()
    >>> op.inputs.num_comp.connect(my_num_comp)
    >>> my_scoping = dpf.Scoping()
    >>> op.inputs.scoping.connect(my_scoping)
    """

    def __init__(self, op: Operator):
        super().__init__(scalars_to_field._spec().inputs, op)
        self._double_or_vector_double = Input(
            scalars_to_field._spec().input_pin(0), 0, op, -1
        )
        self._inputs.append(self._double_or_vector_double)
        self._unit = Input(scalars_to_field._spec().input_pin(1), 1, op, -1)
        self._inputs.append(self._unit)
        self._location = Input(scalars_to_field._spec().input_pin(2), 2, op, -1)
        self._inputs.append(self._location)
        self._num_entity = Input(scalars_to_field._spec().input_pin(3), 3, op, -1)
        self._inputs.append(self._num_entity)
        self._num_comp = Input(scalars_to_field._spec().input_pin(4), 4, op, -1)
        self._inputs.append(self._num_comp)
        self._scoping = Input(scalars_to_field._spec().input_pin(5), 5, op, -1)
        self._inputs.append(self._scoping)

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

        Data of the field, default is 0-field.
        specify a double to have a field of
        same value or specify directly the
        data vector.

        Parameters
        ----------
        my_double_or_vector_double : float

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.double_or_vector_double.connect(my_double_or_vector_double)
        >>> # or
        >>> op.inputs.double_or_vector_double(my_double_or_vector_double)
        """
        return self._double_or_vector_double

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

        Unit symbol (m, hz, kg, ...)

        Parameters
        ----------
        my_unit : str

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.unit.connect(my_unit)
        >>> # or
        >>> op.inputs.unit(my_unit)
        """
        return self._unit

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

        Location of the field ex 'nodal',
        'elementalnodal', 'elemental'...
        default is 'numeric'.

        Parameters
        ----------
        my_location : str

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.location.connect(my_location)
        >>> # or
        >>> op.inputs.location(my_location)
        """
        return self._location

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

        Number of field entities. default is 1 or the
        size of the scoping in input if
        specified.

        Parameters
        ----------
        my_num_entity : int

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.num_entity.connect(my_num_entity)
        >>> # or
        >>> op.inputs.num_entity(my_num_entity)
        """
        return self._num_entity

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

        Number of field components. default is 1.

        Parameters
        ----------
        my_num_comp : int

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.num_comp.connect(my_num_comp)
        >>> # or
        >>> op.inputs.num_comp(my_num_comp)
        """
        return self._num_comp

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

        Scoping.

        Parameters
        ----------
        my_scoping : Scoping

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> op.inputs.scoping.connect(my_scoping)
        >>> # or
        >>> op.inputs.scoping(my_scoping)
        """
        return self._scoping


class OutputsScalarsToField(_Outputs):
    """Intermediate class used to get outputs from
    scalars_to_field operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.scalars_to_field()
    >>> # Connect inputs : op.inputs. ...
    >>> result_field = op.outputs.field()
    """

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

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

        Returns
        ----------
        my_field : Field

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.scalars_to_field()
        >>> # Connect inputs : op.inputs. ...
        >>> result_field = op.outputs.field()
        """  # noqa: E501
        return self._field
