# ruff: noqa: D402,PLR0913
# pyright: reportConstantRedefinition=none
"""The schedule commands module.

These commands are used in the following models:
SS3706A

THIS FILE IS AUTO-GENERATED, IT SHOULD NOT BE MANUALLY MODIFIED.

Please report an issue if one is found.

Attributes and Functions:
    ```
    - schedule.alarm[N].enable
    - schedule.alarm[N].fractionalseconds
    - schedule.alarm[N].period
    - schedule.alarm[N].ptpseconds
    - schedule.alarm[N].repetition
    - schedule.alarm[N].seconds
    - schedule.disable()
    ```
"""

from typing import Dict, Optional, TYPE_CHECKING, Union

from ..helpers import (
    BaseTSPCmd,
    DefaultDictPassKeyToFactory,
    NoDeviceProvidedError,
    ValidatedDynamicNumberCmd,
)

if TYPE_CHECKING:
    from tm_devices.drivers.pi.tsp_device import TSPDevice


class ScheduleAlarmItem(ValidatedDynamicNumberCmd, BaseTSPCmd):
    """The ``schedule.alarm[N]`` command tree.

    Info:
        - ``N``, the alarm number (1 or 2).

    Constants:
        - ``.EVENT_ID``: This constant describes the trigger event generated by the alarm N.

    Properties and methods:
        - ``.enable``: The ``schedule.alarm[N].enable`` attribute.
        - ``.fractionalseconds``: The ``schedule.alarm[N].fractionalseconds`` attribute.
        - ``.period``: The ``schedule.alarm[N].period`` attribute.
        - ``.ptpseconds``: The ``schedule.alarm[N].ptpseconds`` attribute.
        - ``.repetition``: The ``schedule.alarm[N].repetition`` attribute.
        - ``.seconds``: The ``schedule.alarm[N].seconds`` attribute.
    """

    EVENT_ID = "schedule.alarm[N].EVENT_ID"
    """str: This constant describes the trigger event generated by the alarm N."""

    def __init__(self, device: Optional["TSPDevice"], cmd_syntax: str) -> None:
        super().__init__(device, cmd_syntax)
        # pylint: disable=invalid-name
        self.EVENT_ID = self.EVENT_ID.replace(
            "[N]", f"[{self._cmd_syntax.rsplit('[', maxsplit=1)[-1].split(']', maxsplit=1)[0]}]"
        )

    @property
    def enable(self) -> str:
        """Access the ``schedule.alarm[N].enable`` attribute.

        Description:
            - This attribute enables or disables an alarm.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].enable)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].enable = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].enable = value
            - print(schedule.alarm[N].enable)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".enable"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.enable)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.enable`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @enable.setter
    def enable(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].enable`` attribute.

        Description:
            - This attribute enables or disables an alarm.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].enable)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].enable = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].enable = value
            - print(schedule.alarm[N].enable)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".enable", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.enable = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.enable`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @property
    def fractionalseconds(self) -> str:
        """Access the ``schedule.alarm[N].fractionalseconds`` attribute.

        Description:
            - This attribute describes the fractional seconds portion of the alarm time.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].fractionalseconds)``
              query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].fractionalseconds = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].fractionalseconds = value
            - print(schedule.alarm[N].fractionalseconds)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".fractionalseconds"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.fractionalseconds)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.fractionalseconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @fractionalseconds.setter
    def fractionalseconds(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].fractionalseconds`` attribute.

        Description:
            - This attribute describes the fractional seconds portion of the alarm time.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].fractionalseconds)``
              query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].fractionalseconds = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].fractionalseconds = value
            - print(schedule.alarm[N].fractionalseconds)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".fractionalseconds", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.fractionalseconds = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.fractionalseconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @property
    def period(self) -> str:
        """Access the ``schedule.alarm[N].period`` attribute.

        Description:
            - This attribute describes the time, in seconds, between adjacent firings of the alarm.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].period)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].period = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].period = value
            - print(schedule.alarm[N].period)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".period"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.period)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.period`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @period.setter
    def period(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].period`` attribute.

        Description:
            - This attribute describes the time, in seconds, between adjacent firings of the alarm.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].period)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].period = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].period = value
            - print(schedule.alarm[N].period)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".period", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.period = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.period`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @property
    def ptpseconds(self) -> str:
        """Access the ``schedule.alarm[N].ptpseconds`` attribute.

        Description:
            - The seconds portion of the alarm time in PTP seconds.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].ptpseconds)`` query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].ptpseconds = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].ptpseconds = value
            - print(schedule.alarm[N].ptpseconds)
            ```

        Info:
            - ``N``, the alarm (1 or 2).
            - ``seconds``, the seconds portion of the alarm time in PTP seconds.

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".ptpseconds"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.ptpseconds)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.ptpseconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @ptpseconds.setter
    def ptpseconds(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].ptpseconds`` attribute.

        Description:
            - The seconds portion of the alarm time in PTP seconds.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].ptpseconds)`` query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].ptpseconds = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].ptpseconds = value
            - print(schedule.alarm[N].ptpseconds)
            ```

        Info:
            - ``N``, the alarm (1 or 2).
            - ``seconds``, the seconds portion of the alarm time in PTP seconds.

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".ptpseconds", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.ptpseconds = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.ptpseconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @property
    def repetition(self) -> str:
        """Access the ``schedule.alarm[N].repetition`` attribute.

        Description:
            - This attribute describes the number of times an alarm repeats after the first alarm
              firing.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].repetition)`` query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].repetition = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].repetition = value
            - print(schedule.alarm[N].repetition)
            ```

        Info:
            - ``N``, the alarm 1 or 2.

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".repetition"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.repetition)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.repetition`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @repetition.setter
    def repetition(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].repetition`` attribute.

        Description:
            - This attribute describes the number of times an alarm repeats after the first alarm
              firing.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].repetition)`` query.
            - Setting this property to a value will send the
              ``schedule.alarm[N].repetition = value`` command.

        TSP Syntax:
            ```
            - schedule.alarm[N].repetition = value
            - print(schedule.alarm[N].repetition)
            ```

        Info:
            - ``N``, the alarm 1 or 2.

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".repetition", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.repetition = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.repetition`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @property
    def seconds(self) -> str:
        """Access the ``schedule.alarm[N].seconds`` attribute.

        Description:
            - The seconds portion of the alarm time in UTC seconds.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].seconds)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].seconds = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].seconds = value
            - print(schedule.alarm[N].seconds)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_syntax_enabled:  # type: ignore[union-attr]
                return self._cmd_syntax + ".seconds"
            return self._device.query(  # type: ignore[union-attr]
                f"print({self._cmd_syntax}.seconds)"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.seconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error

    @seconds.setter
    def seconds(self, value: Union[str, float]) -> None:
        """Access the ``schedule.alarm[N].seconds`` attribute.

        Description:
            - The seconds portion of the alarm time in UTC seconds.

        Usage:
            - Accessing this property will send the ``print(schedule.alarm[N].seconds)`` query.
            - Setting this property to a value will send the ``schedule.alarm[N].seconds = value``
              command.

        TSP Syntax:
            ```
            - schedule.alarm[N].seconds = value
            - print(schedule.alarm[N].seconds)
            ```

        Info:
            - ``N``, the alarm number (1 or 2).

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            if self._device.command_verification_enabled:  # type: ignore[union-attr]
                self._device.set_and_check(  # type: ignore[union-attr]
                    self._cmd_syntax + ".seconds", value
                )
            else:
                self._device.write(  # type: ignore[union-attr]
                    f"{self._cmd_syntax}.seconds = {value}"
                )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to access the ``{self._cmd_syntax}.seconds`` attribute."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error


class Schedule(BaseTSPCmd):
    """The ``schedule`` command tree.

    Properties and methods:
        - ``.alarm``: The ``schedule.alarm[N]`` command tree.
        - ``.disable()``: The ``schedule.disable()`` function.
    """

    def __init__(self, device: Optional["TSPDevice"] = None, cmd_syntax: str = "schedule") -> None:
        super().__init__(device, cmd_syntax)
        self._alarm: Dict[int, ScheduleAlarmItem] = DefaultDictPassKeyToFactory(
            lambda x: ScheduleAlarmItem(device, f"{self._cmd_syntax}.alarm[{x}]")
        )

    @property
    def alarm(self) -> Dict[int, ScheduleAlarmItem]:
        """Return the ``schedule.alarm[N]`` command tree.

        Info:
            - ``N``, the alarm number (1 or 2).

        Constants:
            - ``.EVENT_ID``: This constant describes the trigger event generated by the alarm N.

        Sub-properties and sub-methods:
            - ``.enable``: The ``schedule.alarm[N].enable`` attribute.
            - ``.fractionalseconds``: The ``schedule.alarm[N].fractionalseconds`` attribute.
            - ``.period``: The ``schedule.alarm[N].period`` attribute.
            - ``.ptpseconds``: The ``schedule.alarm[N].ptpseconds`` attribute.
            - ``.repetition``: The ``schedule.alarm[N].repetition`` attribute.
            - ``.seconds``: The ``schedule.alarm[N].seconds`` attribute.
        """
        return self._alarm

    def disable(self) -> None:
        """Run the ``schedule.disable()`` function.

        Description:
            - This function disables all alarms.

        TSP Syntax:
            ```
            - schedule.disable()
            ```

        Raises:
            tm_devices.commands.NoDeviceProvidedError: Indicates that no device connection exists.
        """
        try:
            self._device.write(  # type: ignore[union-attr]
                f"{self._cmd_syntax}.disable()"
            )
        except AttributeError as error:
            msg = f"No TSPDevice object was provided, unable to run the ``{self._cmd_syntax}.disable()`` function."  # noqa: E501
            raise NoDeviceProvidedError(msg) from error
