"""
producer_consumer_for_each
==========================
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 producer_consumer_for_each(Operator):
    """Allows to write a loop over operators by connecting data to iterate
    and by requesting the incrementally output merged.The chain of
    Operators are split into a first part: the producers and a second
    part: the consumers. These 2 parts will run asynchronously on 2
    threads.

    Parameters
    ----------
    producer_consumer_iterableq :
        The result of the
        make_producer_consumer_for_each_itera
        tor operator.
    forward1 :
        Output of the last operators of the workflow
    forward2 :
        Output of the last operators of the workflow


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

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

    >>> # Make input connections
    >>> my_producer_consumer_iterableq = dpf.()
    >>> op.inputs.producer_consumer_iterableq.connect(my_producer_consumer_iterableq)
    >>> my_forward1 = dpf.()
    >>> op.inputs.forward1.connect(my_forward1)
    >>> my_forward2 = dpf.()
    >>> op.inputs.forward2.connect(my_forward2)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.utility.producer_consumer_for_each(
    ...     producer_consumer_iterableq=my_producer_consumer_iterableq,
    ...     forward1=my_forward1,
    ...     forward2=my_forward2,
    ... )

    >>> # Get output data
    >>> result_output1 = op.outputs.output1()
    >>> result_output2 = op.outputs.output2()
    """

    def __init__(
        self,
        producer_consumer_iterableq=None,
        forward1=None,
        forward2=None,
        config=None,
        server=None,
    ):
        super().__init__(
            name="producer_consumer_for_each", config=config, server=server
        )
        self._inputs = InputsProducerConsumerForEach(self)
        self._outputs = OutputsProducerConsumerForEach(self)
        if producer_consumer_iterableq is not None:
            self.inputs.producer_consumer_iterableq.connect(producer_consumer_iterableq)
        if forward1 is not None:
            self.inputs.forward1.connect(forward1)
        if forward2 is not None:
            self.inputs.forward2.connect(forward2)

    @staticmethod
    def _spec():
        description = """Allows to write a loop over operators by connecting data to iterate
            and by requesting the incrementally output merged.The
            chain of Operators are split into a first part: the
            producers and a second part: the consumers. These 2 parts
            will run asynchronously on 2 threads."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="producer_consumer_iterableq",
                    type_names=["any"],
                    optional=False,
                    document="""The result of the
        make_producer_consumer_for_each_itera
        tor operator.""",
                ),
                3: PinSpecification(
                    name="forward",
                    type_names=["any"],
                    optional=False,
                    document="""Output of the last operators of the workflow""",
                ),
                4: PinSpecification(
                    name="forward",
                    type_names=["any"],
                    optional=False,
                    document="""Output of the last operators of the workflow""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="output1",
                    optional=False,
                    document="""""",
                ),
                1: PinSpecification(
                    name="output2",
                    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="producer_consumer_for_each", server=server)

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

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

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

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


class InputsProducerConsumerForEach(_Inputs):
    """Intermediate class used to connect user inputs to
    producer_consumer_for_each operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.producer_consumer_for_each()
    >>> my_producer_consumer_iterableq = dpf.()
    >>> op.inputs.producer_consumer_iterableq.connect(my_producer_consumer_iterableq)
    >>> my_forward1 = dpf.()
    >>> op.inputs.forward1.connect(my_forward1)
    >>> my_forward2 = dpf.()
    >>> op.inputs.forward2.connect(my_forward2)
    """

    def __init__(self, op: Operator):
        super().__init__(producer_consumer_for_each._spec().inputs, op)
        self._producer_consumer_iterableq = Input(
            producer_consumer_for_each._spec().input_pin(0), 0, op, -1
        )
        self._inputs.append(self._producer_consumer_iterableq)
        self._forward1 = Input(
            producer_consumer_for_each._spec().input_pin(3), 3, op, 0
        )
        self._inputs.append(self._forward1)
        self._forward2 = Input(
            producer_consumer_for_each._spec().input_pin(4), 4, op, 1
        )
        self._inputs.append(self._forward2)

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

        The result of the
        make_producer_consumer_for_each_itera
        tor operator.

        Parameters
        ----------
        my_producer_consumer_iterableq :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.producer_consumer_for_each()
        >>> op.inputs.producer_consumer_iterableq.connect(my_producer_consumer_iterableq)
        >>> # or
        >>> op.inputs.producer_consumer_iterableq(my_producer_consumer_iterableq)
        """
        return self._producer_consumer_iterableq

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

        Output of the last operators of the workflow

        Parameters
        ----------
        my_forward1 :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.producer_consumer_for_each()
        >>> op.inputs.forward1.connect(my_forward1)
        >>> # or
        >>> op.inputs.forward1(my_forward1)
        """
        return self._forward1

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

        Output of the last operators of the workflow

        Parameters
        ----------
        my_forward2 :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.producer_consumer_for_each()
        >>> op.inputs.forward2.connect(my_forward2)
        >>> # or
        >>> op.inputs.forward2(my_forward2)
        """
        return self._forward2


class OutputsProducerConsumerForEach(_Outputs):
    """Intermediate class used to get outputs from
    producer_consumer_for_each operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.producer_consumer_for_each()
    >>> # Connect inputs : op.inputs. ...
    >>> result_output1 = op.outputs.output1()
    >>> result_output2 = op.outputs.output2()
    """

    def __init__(self, op: Operator):
        super().__init__(producer_consumer_for_each._spec().outputs, op)
        self._output1 = Output(producer_consumer_for_each._spec().output_pin(0), 0, op)
        self._outputs.append(self._output1)
        self._output2 = Output(producer_consumer_for_each._spec().output_pin(1), 1, op)
        self._outputs.append(self._output2)

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

        Returns
        ----------
        my_output1 :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.producer_consumer_for_each()
        >>> # Connect inputs : op.inputs. ...
        >>> result_output1 = op.outputs.output1()
        """  # noqa: E501
        return self._output1

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

        Returns
        ----------
        my_output2 :

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.producer_consumer_for_each()
        >>> # Connect inputs : op.inputs. ...
        >>> result_output2 = op.outputs.output2()
        """  # noqa: E501
        return self._output2
