"""
server_path
===========
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 server_path(Operator):
    """Returns the platform-specific path to a folder in the Dpf server

    Parameters
    ----------
    subpath : int, optional
        Subpath of the dpf server. supported values:
        0 (default): root of the server, 1:
        "dpf/bin/platform", 2:
        "aisol/bin(dll)/platform", 3:
        "dpf/plugins".


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

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

    >>> # Make input connections
    >>> my_subpath = int()
    >>> op.inputs.subpath.connect(my_subpath)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.utility.server_path(
    ...     subpath=my_subpath,
    ... )

    >>> # Get output data
    >>> result_path = op.outputs.path()
    """

    def __init__(self, subpath=None, config=None, server=None):
        super().__init__(name="server_path", config=config, server=server)
        self._inputs = InputsServerPath(self)
        self._outputs = OutputsServerPath(self)
        if subpath is not None:
            self.inputs.subpath.connect(subpath)

    @staticmethod
    def _spec():
        description = (
            """Returns the platform-specific path to a folder in the Dpf server"""
        )
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="subpath",
                    type_names=["int32"],
                    optional=True,
                    document="""Subpath of the dpf server. supported values:
        0 (default): root of the server, 1:
        "dpf/bin/platform", 2:
        "aisol/bin(dll)/platform", 3:
        "dpf/plugins".""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="path",
                    type_names=["string"],
                    optional=False,
                    document="""Path to the requested folder in the dpf
        server""",
                ),
            },
        )
        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="server_path", server=server)

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

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

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

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


class InputsServerPath(_Inputs):
    """Intermediate class used to connect user inputs to
    server_path operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.server_path()
    >>> my_subpath = int()
    >>> op.inputs.subpath.connect(my_subpath)
    """

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

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

        Subpath of the dpf server. supported values:
        0 (default): root of the server, 1:
        "dpf/bin/platform", 2:
        "aisol/bin(dll)/platform", 3:
        "dpf/plugins".

        Parameters
        ----------
        my_subpath : int

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.server_path()
        >>> op.inputs.subpath.connect(my_subpath)
        >>> # or
        >>> op.inputs.subpath(my_subpath)
        """
        return self._subpath


class OutputsServerPath(_Outputs):
    """Intermediate class used to get outputs from
    server_path operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.utility.server_path()
    >>> # Connect inputs : op.inputs. ...
    >>> result_path = op.outputs.path()
    """

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

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

        Returns
        ----------
        my_path : str

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.utility.server_path()
        >>> # Connect inputs : op.inputs. ...
        >>> result_path = op.outputs.path()
        """  # noqa: E501
        return self._path
