"""
hdf5dpf_generate_result_file
============================
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 hdf5dpf_generate_result_file(Operator):
    """Generate a dpf result file from provided information.

    Parameters
    ----------
    filename : str
        Name of the output file that will be
        generated (utf8).
    mesh_provider_out : MeshedRegion, optional
        Defines the meshedregion that is exported and
        provided by meshprovider.
    time_freq_support_out : TimeFreqSupport, optional
        Defines the timefreqsupport that is exported
        and provided by
        timefreqsupportprovider.
    ansys_unit_system_id : int, optional
        Defines the unitsystem the results are
        exported with.


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

    >>> # Instantiate operator
    >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()

    >>> # Make input connections
    >>> my_filename = str()
    >>> op.inputs.filename.connect(my_filename)
    >>> my_mesh_provider_out = dpf.MeshedRegion()
    >>> op.inputs.mesh_provider_out.connect(my_mesh_provider_out)
    >>> my_time_freq_support_out = dpf.TimeFreqSupport()
    >>> op.inputs.time_freq_support_out.connect(my_time_freq_support_out)
    >>> my_ansys_unit_system_id = int()
    >>> op.inputs.ansys_unit_system_id.connect(my_ansys_unit_system_id)

    >>> # Instantiate operator and connect inputs in one line
    >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file(
    ...     filename=my_filename,
    ...     mesh_provider_out=my_mesh_provider_out,
    ...     time_freq_support_out=my_time_freq_support_out,
    ...     ansys_unit_system_id=my_ansys_unit_system_id,
    ... )

    >>> # Get output data
    >>> result_data_sources = op.outputs.data_sources()
    """

    def __init__(
        self,
        filename=None,
        mesh_provider_out=None,
        time_freq_support_out=None,
        ansys_unit_system_id=None,
        config=None,
        server=None,
    ):
        super().__init__(
            name="hdf5::h5dpf::make_result_file", config=config, server=server
        )
        self._inputs = InputsHdf5DpfGenerateResultFile(self)
        self._outputs = OutputsHdf5DpfGenerateResultFile(self)
        if filename is not None:
            self.inputs.filename.connect(filename)
        if mesh_provider_out is not None:
            self.inputs.mesh_provider_out.connect(mesh_provider_out)
        if time_freq_support_out is not None:
            self.inputs.time_freq_support_out.connect(time_freq_support_out)
        if ansys_unit_system_id is not None:
            self.inputs.ansys_unit_system_id.connect(ansys_unit_system_id)

    @staticmethod
    def _spec():
        description = """Generate a dpf result file from provided information."""
        spec = Specification(
            description=description,
            map_input_pin_spec={
                0: PinSpecification(
                    name="filename",
                    type_names=["string"],
                    optional=False,
                    document="""Name of the output file that will be
        generated (utf8).""",
                ),
                1: PinSpecification(
                    name="mesh_provider_out",
                    type_names=["abstract_meshed_region"],
                    optional=True,
                    document="""Defines the meshedregion that is exported and
        provided by meshprovider.""",
                ),
                2: PinSpecification(
                    name="time_freq_support_out",
                    type_names=["time_freq_support"],
                    optional=True,
                    document="""Defines the timefreqsupport that is exported
        and provided by
        timefreqsupportprovider.""",
                ),
                3: PinSpecification(
                    name="ansys_unit_system_id",
                    type_names=["int32"],
                    optional=True,
                    document="""Defines the unitsystem the results are
        exported with.""",
                ),
            },
            map_output_pin_spec={
                0: PinSpecification(
                    name="data_sources",
                    type_names=["data_sources"],
                    optional=False,
                    document="""Data_sources filed with the h5 generated file
        path.""",
                ),
            },
        )
        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="hdf5::h5dpf::make_result_file", server=server
        )

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

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

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

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


class InputsHdf5DpfGenerateResultFile(_Inputs):
    """Intermediate class used to connect user inputs to
    hdf5dpf_generate_result_file operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
    >>> my_filename = str()
    >>> op.inputs.filename.connect(my_filename)
    >>> my_mesh_provider_out = dpf.MeshedRegion()
    >>> op.inputs.mesh_provider_out.connect(my_mesh_provider_out)
    >>> my_time_freq_support_out = dpf.TimeFreqSupport()
    >>> op.inputs.time_freq_support_out.connect(my_time_freq_support_out)
    >>> my_ansys_unit_system_id = int()
    >>> op.inputs.ansys_unit_system_id.connect(my_ansys_unit_system_id)
    """

    def __init__(self, op: Operator):
        super().__init__(hdf5dpf_generate_result_file._spec().inputs, op)
        self._filename = Input(
            hdf5dpf_generate_result_file._spec().input_pin(0), 0, op, -1
        )
        self._inputs.append(self._filename)
        self._mesh_provider_out = Input(
            hdf5dpf_generate_result_file._spec().input_pin(1), 1, op, -1
        )
        self._inputs.append(self._mesh_provider_out)
        self._time_freq_support_out = Input(
            hdf5dpf_generate_result_file._spec().input_pin(2), 2, op, -1
        )
        self._inputs.append(self._time_freq_support_out)
        self._ansys_unit_system_id = Input(
            hdf5dpf_generate_result_file._spec().input_pin(3), 3, op, -1
        )
        self._inputs.append(self._ansys_unit_system_id)

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

        Name of the output file that will be
        generated (utf8).

        Parameters
        ----------
        my_filename : str

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
        >>> op.inputs.filename.connect(my_filename)
        >>> # or
        >>> op.inputs.filename(my_filename)
        """
        return self._filename

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

        Defines the meshedregion that is exported and
        provided by meshprovider.

        Parameters
        ----------
        my_mesh_provider_out : MeshedRegion

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
        >>> op.inputs.mesh_provider_out.connect(my_mesh_provider_out)
        >>> # or
        >>> op.inputs.mesh_provider_out(my_mesh_provider_out)
        """
        return self._mesh_provider_out

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

        Defines the timefreqsupport that is exported
        and provided by
        timefreqsupportprovider.

        Parameters
        ----------
        my_time_freq_support_out : TimeFreqSupport

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
        >>> op.inputs.time_freq_support_out.connect(my_time_freq_support_out)
        >>> # or
        >>> op.inputs.time_freq_support_out(my_time_freq_support_out)
        """
        return self._time_freq_support_out

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

        Defines the unitsystem the results are
        exported with.

        Parameters
        ----------
        my_ansys_unit_system_id : int

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
        >>> op.inputs.ansys_unit_system_id.connect(my_ansys_unit_system_id)
        >>> # or
        >>> op.inputs.ansys_unit_system_id(my_ansys_unit_system_id)
        """
        return self._ansys_unit_system_id


class OutputsHdf5DpfGenerateResultFile(_Outputs):
    """Intermediate class used to get outputs from
    hdf5dpf_generate_result_file operator.

    Examples
    --------
    >>> from ansys.dpf import core as dpf
    >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
    >>> # Connect inputs : op.inputs. ...
    >>> result_data_sources = op.outputs.data_sources()
    """

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

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

        Returns
        ----------
        my_data_sources : DataSources

        Examples
        --------
        >>> from ansys.dpf import core as dpf
        >>> op = dpf.operators.serialization.hdf5dpf_generate_result_file()
        >>> # Connect inputs : op.inputs. ...
        >>> result_data_sources = op.outputs.data_sources()
        """  # noqa: E501
        return self._data_sources
