"""Autogenerated module for the DAQModule QCoDeS driver."""
import typing as t
from zhinst.toolkit.driver.modules.daq_module import DAQModule as TKDAQModule

from zhinst.qcodes.driver.modules.base_module import ZIBaseModule

from zhinst.qcodes.qcodes_adaptions import (
    NodeDict,
)

if t.TYPE_CHECKING:
    from zhinst.qcodes.session import Session


class ZIDAQModule(ZIBaseModule):
    """Data Acquisition Module.

    The Data Acquisition Module corresponds to the Data Acquisition tab of the
    LabOne User Interface. It enables the user to record and align time and
    frequency domain data from multiple instrument signal sources at a defined
    data rate. The data may be recorded either continuously or in bursts based
    upon trigger criteria analogous to the functionality provided by laboratory
    oscilloscopes.

    For a complete documentation see the LabOne user manual
    https://docs.zhinst.com/labone_programming_manual/data_acquisition_module.html


    Args:
        tk_object: Underlying zhinst-toolkit object.
        session: Session to the Data Server.
        name: Name of the module in QCoDeS.
    """

    def __init__(
        self, tk_object: TKDAQModule, session: "Session", name: str = "daq_module"
    ):
        super().__init__(tk_object, session, name)

        self._tk_object.root.update_nodes(
            {
                "/triggernode": {
                    "GetParser": lambda value: self._get_node(value),
                    "SetParser": lambda value: self._set_node(value),
                }
            },
            raise_for_invalid_node=False,
        )

    def finish(self) -> None:
        """Stop the module.

        .. versionadded:: 0.5.0
        """
        return self._tk_object.finish()

    def finished(self) -> bool:
        """Check if the acquisition has finished.

        Returns:
            Flag if the acquisition has finished.

        .. versionadded:: 0.5.0
        """
        return self._tk_object.finished()

    def trigger(self) -> None:
        """Execute a manual trigger.

        .. versionadded:: 0.5.0
        """
        return self._tk_object.trigger()

    def read(self, *, raw: bool = False, clk_rate: float = 60000000.0) -> NodeDict:
        """Read the acquired data from the module.

        The data is split into bursts.

        Args:
            raw: Flag if the acquired data from the subscribed device
                device nodes should be converted into the DAQResult format
                (raw = False) or not. (default = False)
            clk_rate: Clock rate [Hz] for converting the timestamps. Only
                applies if the raw flag is reset.

        Returns:
            Result of the burst grouped by the signals.
        """
        return NodeDict(self._tk_object.read(raw=raw, clk_rate=clk_rate))
