from UniTAP.dev.ports import DPRX4xx, DPTX4xx, HDRX4xx, HDTX4xx, PDC424
from .modules import MemoryManager, Capturer, DUTTests
from UniTAP.libs.lib_tsi.tsi_io import DeviceIO, PortProtocol


class UCD400:
    """
    Class `UCD400` describes of device UCD-400. Device has one possible role:
    - 'DisplayPort Source and Sink' `DPSourceDPSink`
    """
    class DPSourceDPSink:
        """
        Class `DPSourceDPSink` contains information of available functionality modules for role DP Sink
        (RX - receiver) and DP Source (TX - transmitter) roles:
        - `DPRX4xx`.
        - `DPTX4xx`.
        - `DUTTests`.
        """
        def __init__(self, dev_io: DeviceIO, memory_manager: MemoryManager, capturer: Capturer):
            super().__init__()
            self.__dprx = DPRX4xx(dev_io.create_port_io(0, PortProtocol.DisplayPort), memory_manager, capturer)
            self.__dptx = DPTX4xx(dev_io.create_port_io(1, PortProtocol.DisplayPort), memory_manager, capturer)
            self.__dut_tests = DUTTests(dev_io)

        @property
        def dprx(self) -> DPRX4xx:
            """
            Returns DP Sink (RX - receiver) role.

            Returns:
                object of DPRX4xx type.
            """
            return self.__dprx

        @property
        def dptx(self) -> DPTX4xx:
            """
            Returns DP Source (TX - transmitter) role.

            Returns:
                object of DPTX4xx type.
            """
            return self.__dptx

        @property
        def dut_tests(self) -> DUTTests:
            """
            Returns DUT Test module.

            Returns:
                object of DUTTests type.
            """
            return self.__dut_tests

        @property
        def name(self) -> str:
            """
            Returns name of role.

            Returns:
                object of str type.
            """
            return list(UCD400.ROLE_DICT.keys())[list(UCD400.ROLE_DICT.values()).index(type(self))]

    ROLE_DICT = {
        "DisplayPort Source and Sink": DPSourceDPSink
    }


class UCD422:
    """
    Class `UCD422` describes of device UCD-422. Device has one possible role:
    - 'HDMI Source and Sink' `HDMISourceHDMISink`
    """
    class HDMISourceHDMISink:
        """
        Class `DPSourceDPSink` contains information of available functionality modules for role HDMI Sink
        (RX - receiver) and HDMI Source (TX - transmitter) roles:
        - `HDRX4xx`.
        - `HDTX4xx`.
        - `DUTTests`.
        """
        def __init__(self, dev_io: DeviceIO, memory_manager: MemoryManager, capturer: Capturer):
            super().__init__()
            self.__hdrx = HDRX4xx(dev_io.create_port_io(0, PortProtocol.HDMI), memory_manager, capturer)
            self.__hdtx = HDTX4xx(dev_io.create_port_io(1, PortProtocol.HDMI), memory_manager, capturer)
            self.__dut_tests = DUTTests(dev_io)

        @property
        def hdtx(self) -> HDTX4xx:
            """
            Returns HDMI Source (TX - transmitter) role.

            Returns:
                object of HDTX4xx type.
            """
            return self.__hdtx

        @property
        def hdrx(self) -> HDRX4xx:
            """
            Returns HDMI Sink (RX - receiver) role.

            Returns:
                object of HDRX4xx type.
            """
            return self.__hdrx

        @property
        def dut_tests(self) -> DUTTests:
            """
            Returns DUT Test module.

            Returns:
                object of DUTTests type.
            """
            return self.__dut_tests

        @property
        def name(self) -> str:
            """
            Returns name of role.

            Returns:
                object of str type.
            """
            return list(UCD422.ROLE_DICT.keys())[list(UCD422.ROLE_DICT.values()).index(type(self))]

    ROLE_DICT = {
        "HDMI Source and Sink": HDMISourceHDMISink
    }


class UCD424:
    """
    Class `UCD424` describes of device UCD-424. Device has one possible role:
    - 'USB-C Source and Sink' `USBCSourceUSBCSink`.
    """
    class USBCSourceUSBCSink:
        """
        Class `DPSourceDPSink` contains information of available functionality modules for role HDMI Sink
        (RX - receiver) and HDMI Source (TX - transmitter) roles:
        - `DPRX4xx`.
        - `DPTX4xx`.
        - `DUTTests`.
        - `PDC`.
        """
        def __init__(self, dev_io: DeviceIO, memory_manager: MemoryManager, capturer: Capturer):
            super().__init__()
            self.__port_rx = dev_io.create_port_io(0, PortProtocol.DisplayPortThrowUSBC)
            self.__port_tx = dev_io.create_port_io(1, PortProtocol.DisplayPortThrowUSBC)
            self.__dprx = DPRX4xx(self.__port_rx, memory_manager, capturer)
            self.__dptx = DPTX4xx(self.__port_tx, memory_manager, capturer)
            self.__dut_tests = DUTTests(dev_io)
            self.__pdcrx = PDC424(self.__port_rx)
            self.__pdctx = PDC424(self.__port_tx)

        @property
        def dprx(self) -> DPRX4xx:
            """
            Returns DP Sink (RX - receiver) role.

            Returns:
                object of DPRX4xx type.
            """
            return self.__dprx

        @property
        def dptx(self) -> DPTX4xx:
            """
            Returns DP Source (TX - transmitter) role.

            Returns:
                object of DPTX4xx type.
            """
            return self.__dptx

        @property
        def pdcrx(self) -> PDC424:
            """
            Returns PDC Sink (RX - receiver) role.

            Returns:
                object of `PDC424` type.
            """
            return self.__pdcrx

        @property
        def pdctx(self) -> PDC424:
            """
            Returns PDC source (TX - transmitter) role.

            Returns:
                object of `PDC424` type.
            """
            return self.__pdctx

        @property
        def dut_tests(self) -> DUTTests:
            """
            Returns DUT Test module.

            Returns:
                object of DUTTests type.
            """
            return self.__dut_tests

        @property
        def name(self) -> str:
            """
            Returns name of role.

            Returns:
                object of str type.
            """
            return list(UCD424.ROLE_DICT.keys())[list(UCD424.ROLE_DICT.values()).index(type(self))]

    ROLE_DICT = {
        "USB-C Source and Sink": USBCSourceUSBCSink
    }
