"""
average_over_label_fc
=====================
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 average_over_label_fc(Operator):
    """Compute the component-wise average over all the fields that have the
    same ID as the label set as input in the fields container. This
    computation can be incremental. If the input fields container is
    connected and the operator is run multiple times, the output field
    will be on all the connected inputs.

    Parameters
    ----------
    fields_container : FieldsContainer
    label : str, optional
        Label of the fields container where it should
        operate.


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

    >>> # Instantiate operator
    >>> op = dpf.operators.math.average_over_label_fc()

    >>> # Make input connections
    >>> my_fields_container = dpf.FieldsContainer()
    >>> op.inputs.fields_container.connect(my_fields_container)
    >>> my_label = str()
    >>> op.inputs.label.connect(my_label)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.math.average_over_label_fc(
    ...     fields_container=my_fields_container,
    ...     label=my_label,
    ... )

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

    def __init__(self, fields_container=None, label=None, config=None, server=None):
        super().__init__(name="average_over_label_fc", config=config, server=server)
        self._inputs = InputsAverageOverLabelFc(self)
        self._outputs = OutputsAverageOverLabelFc(self)
        if fields_container is not None:
            self.inputs.fields_container.connect(fields_container)
        if label is not None:
            self.inputs.label.connect(label)

    @staticmethod
    def _spec():
        description = """Compute the component-wise average over all the fields that have the
            same ID as the label set as input in the fields container.
            This computation can be incremental. If the input fields
            container is connected and the operator is run multiple
            times, the output field will be on all the connected
            inputs."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="fields_container",
                    type_names=["fields_container"],
                    optional=False,
                    document="""""",
                ),
                1: PinSpecification(
                    name="label",
                    type_names=["string"],
                    optional=True,
                    document="""Label of the fields container where it should
        operate.""",
                ),
            },
            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="average_over_label_fc", server=server)

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

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

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

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


class InputsAverageOverLabelFc(_Inputs):
    """Intermediate class used to connect user inputs to
    average_over_label_fc operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.math.average_over_label_fc()
    >>> my_fields_container = dpf.FieldsContainer()
    >>> op.inputs.fields_container.connect(my_fields_container)
    >>> my_label = str()
    >>> op.inputs.label.connect(my_label)
    """

    def __init__(self, op: Operator):
        super().__init__(average_over_label_fc._spec().inputs, op)
        self._fields_container = Input(
            average_over_label_fc._spec().input_pin(0), 0, op, -1
        )
        self._inputs.append(self._fields_container)
        self._label = Input(average_over_label_fc._spec().input_pin(1), 1, op, -1)
        self._inputs.append(self._label)

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

        Parameters
        ----------
        my_fields_container : FieldsContainer

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.math.average_over_label_fc()
        >>> op.inputs.fields_container.connect(my_fields_container)
        >>> # or
        >>> op.inputs.fields_container(my_fields_container)
        """
        return self._fields_container

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

        Label of the fields container where it should
        operate.

        Parameters
        ----------
        my_label : str

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.math.average_over_label_fc()
        >>> op.inputs.label.connect(my_label)
        >>> # or
        >>> op.inputs.label(my_label)
        """
        return self._label


class OutputsAverageOverLabelFc(_Outputs):
    """Intermediate class used to get outputs from
    average_over_label_fc operator.

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

    def __init__(self, op: Operator):
        super().__init__(average_over_label_fc._spec().outputs, op)
        self._field = Output(average_over_label_fc._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.math.average_over_label_fc()
        >>> # Connect inputs : op.inputs. ...
        >>> result_field = op.outputs.field()
        """  # noqa: E501
        return self._field
