from UniTAP.libs.lib_tsi.tsi_io import PortIO
from .pr_sink_private_types import SinkPanelSelfRefreshStatusStruct, SinkPanelReplayStatusStruct
from .pr_sink_types import (SinkPRStatusFlags, SelfStatus, FrameStatus, SinkPSRStatusFlags, PRSSelfRefreshStatus)
from UniTAP.libs.lib_tsi.tsi import *


class SinkPanelReplayStatus:
    """
    Class `SinkPanelReplayStatus` contains information about Sink Panel Replay Status.
    - Get Flags status `flags`.
    - Get Debug status `debug`.
    """

    def __init__(self, port_io: PortIO):
        self.__io = port_io

    def flags(self) -> SinkPRStatusFlags:
        """
        Returns current flags status.

        Returns:
            object of `SinkPRStatusFlags` type
        """
        pr_flags = self.__read()
        return SinkPRStatusFlags(active_frame_crc_err=pr_flags.active_frame_crc_err,
                                 rfb_storage_err=pr_flags.rfb_storage_err,
                                 vsc_sdp_err=pr_flags.vsc_sdp_err,  ass_dp_missing=pr_flags.ass_dp_missing,
                                 self_status=SelfStatus(pr_flags.self_status),
                                 frame_locked=FrameStatus(pr_flags.frame_locked),
                                 frame_locked_status_valid=pr_flags.frame_locked_status_valid)

    def __read(self) -> SinkPanelReplayStatusStruct:

        return self.__io.get(TSI_DPRX_PR_STATUS, SinkPanelReplayStatusStruct)[1]


class SinkPanelSelfRefreshStatus:
    """
    Class `SinkPanelReplayStatus` contains information about Sink Panel Self Refresh Status.
    - Get Flags status `flags`.
    - Get Debug status `debug`.
    """

    def __init__(self, port_io: PortIO):
        self.__io = port_io

    def flags(self) -> SinkPSRStatusFlags:
        """
        Returns current flags status.

        Returns:
            object of `SinkPSRStatusFlags` type
        """
        pr_flags = self.__read()
        return SinkPSRStatusFlags(link_crc_err=pr_flags.link_crc_err,
                                  rfb_storage_err=pr_flags.rfb_storage_err,
                                  vsc_sdp_err=pr_flags.vsc_sdp_err,
                                  su_psr_caps_change=pr_flags.su_psr_caps_change,
                                  self_refresh=PRSSelfRefreshStatus(pr_flags.self_refresh))

    def __read(self) -> SinkPanelSelfRefreshStatusStruct:
        return self.__io.get(TSI_DPRX_PSR_STATUS, SinkPanelSelfRefreshStatusStruct)[1]
