from .test_info import *


class MergedTestGroups(IntEnum):
    Unknown = 0x00
    CRCVideoTest = 0x01
    AudioTest = 0x02
    DPRX_8b10b_LL_CTS = 0x03
    LinkConfigTest = 0x04
    DPRX_ELECTRICAL = 0x05
    HDRX_ELECTRICAL = 0x06
    USBC_ELECTRICAL = 0x07
    DPRX_128b132b_LL_CTS = 0x08
    DP_HDCP_CTS_1A = 0x09
    DP_HDCP_CTS_1B = 0x0A
    DP_HDCP_CTS_3A = 0x0B
    DP_HDCP_CTS_3B = 0x0C
    DP_HDCP_CTS_2C = 0x0D
    DP_HDCP_CTS_3C = 0x0E
    HD_TX_VRR = 0x0F
    HD_RX_VRR = 0x10
    HD_RX_CEC = 0x11
    PixelVideoTest = 0x12
    DPTX_8b10b_LL_CTS = 0x13
    HDR10PlusSourceTest = 0x14,
    LTTPR_128b132b_LL_CTS = 0x15,
    HDR10PlusSSTMTest = 0x16,
    EPRPowerSink = 0x17,
    DPTX_128b132b_LL_CTS = 0x18,
    EPRPowerSource = 0x19,
    HDRX_DSC_CTS = 0x20,
    HDTX_DSC_CTS = 0x21,
    HDTX_CONTINUITY = 0x22,
    HDTX_CABLE_CHECK = 0x24


MERGED_GROUP_PARAMS_TYPE = {
    MergedTestGroups.CRCVideoTest: CrcVideoTestParam,
    MergedTestGroups.AudioTest: AudioTestParam,
    MergedTestGroups.DPRX_8b10b_LL_CTS: Dp14SourceDUTTestParam,
    MergedTestGroups.LinkConfigTest: LinkConfigTestParam,
    MergedTestGroups.DPRX_ELECTRICAL: DpElectricalTestParam,
    MergedTestGroups.HDRX_ELECTRICAL: HdmiElectricalTestParam,
    MergedTestGroups.USBC_ELECTRICAL: UsbcElectricalTestParam,
    MergedTestGroups.DPRX_128b132b_LL_CTS: Dp21SourceDUTTestParam,
    MergedTestGroups.DP_HDCP_CTS_1A: Hdcp1ATestParam,
    MergedTestGroups.DP_HDCP_CTS_1B: Hdcp1BTestParam,
    MergedTestGroups.DP_HDCP_CTS_3A: Hdcp3ATestParam,
    MergedTestGroups.DP_HDCP_CTS_3B: Hdcp3BTestParam,
    MergedTestGroups.DP_HDCP_CTS_2C: Hdcp2CTestParam,
    MergedTestGroups.DP_HDCP_CTS_3C: Hdcp3CTestParam,
    MergedTestGroups.HD_TX_VRR: VrrSinkDUTTestParam,
    MergedTestGroups.HD_RX_VRR: VrrSourceDUTTestParam,
    MergedTestGroups.HD_RX_CEC: CecFunctionalTestParam,
    MergedTestGroups.PixelVideoTest: VideoPixelTestParam,
    MergedTestGroups.DPTX_8b10b_LL_CTS: Dp14SinkTestParam,
    MergedTestGroups.HDR10PlusSourceTest: Hdr10TestParam,
    MergedTestGroups.DPTX_128b132b_LL_CTS: Dp21SinkTestParam,
    MergedTestGroups.LTTPR_128b132b_LL_CTS: DpLttprTestParam,
    MergedTestGroups.HDRX_DSC_CTS: HdmiSourceDUTTestParam,
    MergedTestGroups.HDTX_DSC_CTS: HdmiSinkDUTTestParam,
    MergedTestGroups.HDTX_CONTINUITY: HdmiSinkContinuityDUTTestParam,
    MergedTestGroups.HDTX_CABLE_CHECK: HdmiSinkCableCheckTestParam
}

group_params_dict = {
    TestGroupId.AUDIO_TEST: AudioTestParam,
    TestGroupId.DP_RX_ELECTRICAL: DpElectricalTestParam,
    TestGroupId.HDMI_RX_ELECTRICAL: HdmiElectricalTestParam,
    TestGroupId.CEC_FUNCTIONAL: CecFunctionalTestParam,
    TestGroupId.DP_RX_CRC: CrcVideoTestParam,
    TestGroupId.DP_RX_SIMPLE_LT: LinkConfigTestParam,
    TestGroupId.HDMI_RX_CRC: CrcVideoTestParam,
    TestGroupId.USB_TYPE_C_ELECTRICAL: UsbcElectricalTestParam,
    TestGroupId.DP_RX_LL_CTS: Dp14SourceDUTTestParam,
    TestGroupId.DP_TX_LL_CTS: Dp14SinkTestParam,
    TestGroupId.DP_TX_LL_CTS_DSC: Dp14SinkTestParam,
    TestGroupId.DP_RX_LL_CTS_DSC: Dp14SourceDUTTestParam,
    TestGroupId.DP_2_1_RX_LL_CTS: Dp21SourceDUTTestParam,
    TestGroupId.DP_2_1_TX_LL_CTS: Dp21SinkTestParam,
    TestGroupId.DP_HDCP_CTS_1A: Hdcp1ATestParam,
    TestGroupId.DP_HDCP_CTS_1B: Hdcp1BTestParam,
    TestGroupId.DP_HDCP_CTS_2C: Hdcp2CTestParam,
    TestGroupId.DP_HDCP_CTS_3A: Hdcp3ATestParam,
    TestGroupId.DP_HDCP_CTS_3B: Hdcp3BTestParam,
    TestGroupId.DP_HDCP_CTS_3C: Hdcp3CTestParam,
    TestGroupId.DP_TX_DISPLAYID: Dp14SinkTestParam,
    TestGroupId.DP_RX_DISPLAYID: Dp14SourceDUTTestParam,
    TestGroupId.HDMI_RX_VRR: VrrSourceDUTTestParam,
    TestGroupId.HDMI_TX_VRR: VrrSinkDUTTestParam,
    TestGroupId.DP_TX_ADAPTIVESYNC: Dp14SinkTestParam,
    TestGroupId.DP_RX_ADAPTIVESYNC: Dp14SourceDUTTestParam,
    TestGroupId.DP_2_1_RX_LTTPR_CTS: Dp21SourceDUTTestParam,
    TestGroupId.DP_2_1_TX_LTTPR_CTS: Dp21SinkTestParam,
    TestGroupId.DP_2_1_RX_DSC_CTS: Dp21SourceDUTTestParam,
    TestGroupId.DP_2_1_TX_DSC_CTS: Dp21SinkTestParam,
    TestGroupId.DP_2_1_RX_DISPAYID: Dp21SourceDUTTestParam,
    TestGroupId.DP_2_1_TX_DISPAYID: Dp21SinkTestParam,
    TestGroupId.DP_2_1_RX_ADAPTIVESYNC: Dp21SourceDUTTestParam,
    TestGroupId.DP_2_1_TX_ADAPTIVESYNC: Dp21SinkTestParam,
    TestGroupId.PIXEL_VIDEO_TEST: VideoPixelTestParam,
    TestGroupId.HDR10_TEST: Hdr10TestParam,
    TestGroupId.DP_2_1_LTTPR_CTS: DpLttprTestParam,
    TestGroupId.HD_RX_DSC_CTS: HdmiSourceDUTTestParam,
    TestGroupId.HD_TX_DSC_CTS: HdmiSinkDUTTestParam,
    TestGroupId.HD_TX_CONTINUITY: HdmiSinkContinuityDUTTestParam,
    TestGroupId.HD_TX_CABLE_CHECK: HdmiSinkCableCheckTestParam
}


def test_group_to_merged_group(fw_group: TestGroupId, test_id: int) -> MergedTestGroups:
    merged_group_id = MergedTestGroups.Unknown
    if fw_group == TestGroupId.AUDIO_TEST or fw_group == TestGroupId.PIXEL_VIDEO_TEST:
        if test_id == 0x02:
            merged_group_id = MergedTestGroups.PixelVideoTest
        elif test_id == 0x12:
            merged_group_id = MergedTestGroups.AudioTest
    elif fw_group in [TestGroupId.DP_RX_LL_CTS, TestGroupId.DP_RX_LL_CTS_DSC, TestGroupId.DP_RX_ADAPTIVESYNC,
                      TestGroupId.DP_RX_DISPLAYID]:
        merged_group_id = MergedTestGroups.DPRX_8b10b_LL_CTS
    elif fw_group in [TestGroupId.DP_TX_LL_CTS, TestGroupId.DP_TX_LL_CTS_DSC, TestGroupId.DP_TX_ADAPTIVESYNC,
                      TestGroupId.DP_TX_DISPLAYID]:
        merged_group_id = MergedTestGroups.DPTX_8b10b_LL_CTS
    elif fw_group == TestGroupId.DP_RX_CRC:
        merged_group_id = MergedTestGroups.CRCVideoTest
    elif fw_group == TestGroupId.HDMI_RX_CRC:
        merged_group_id = MergedTestGroups.CRCVideoTest
    elif fw_group in [TestGroupId.DP_2_1_RX_LL_CTS, TestGroupId.DP_2_1_RX_DSC_CTS,
                      TestGroupId.DP_2_1_RX_LTTPR_CTS, TestGroupId.DP_2_1_RX_DISPAYID,
                      TestGroupId.DP_2_1_RX_ADAPTIVESYNC]:
        merged_group_id = MergedTestGroups.DPRX_128b132b_LL_CTS
    elif fw_group in [TestGroupId.DP_2_1_TX_LL_CTS, TestGroupId.DP_2_1_TX_DSC_CTS,
                      TestGroupId.DP_2_1_TX_LTTPR_CTS, TestGroupId.DP_2_1_TX_DISPAYID,
                      TestGroupId.DP_2_1_TX_ADAPTIVESYNC]:
        merged_group_id = MergedTestGroups.DPTX_128b132b_LL_CTS
    elif fw_group == TestGroupId.DP_2_1_LTTPR_CTS:
        merged_group_id = MergedTestGroups.LTTPR_128b132b_LL_CTS
    elif fw_group == TestGroupId.DP_HDCP_CTS_1A:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_1A
    elif fw_group == TestGroupId.DP_HDCP_CTS_1B:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_1B
    elif fw_group == TestGroupId.DP_HDCP_CTS_2C:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_2C
    elif fw_group == TestGroupId.DP_HDCP_CTS_3A:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_3A
    elif fw_group == TestGroupId.DP_HDCP_CTS_3B:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_3B
    elif fw_group == TestGroupId.DP_HDCP_CTS_3C:
        merged_group_id = MergedTestGroups.DP_HDCP_CTS_3C
    elif fw_group == TestGroupId.DP_RX_ELECTRICAL:
        merged_group_id = MergedTestGroups.DPRX_ELECTRICAL
    elif fw_group == TestGroupId.HDMI_RX_ELECTRICAL:
        merged_group_id = MergedTestGroups.HDRX_ELECTRICAL
    elif fw_group == TestGroupId.USB_TYPE_C_ELECTRICAL:
        merged_group_id = MergedTestGroups.USBC_ELECTRICAL
    elif fw_group == TestGroupId.DP_RX_SIMPLE_LT:
        merged_group_id = MergedTestGroups.LinkConfigTest
    elif fw_group == TestGroupId.CEC_FUNCTIONAL:
        merged_group_id = MergedTestGroups.HD_RX_CEC
    elif fw_group == TestGroupId.HDMI_RX_VRR:
        merged_group_id = MergedTestGroups.HD_RX_VRR
    elif fw_group == TestGroupId.HDMI_TX_VRR:
        merged_group_id = MergedTestGroups.HD_TX_VRR
    elif fw_group == TestGroupId.HD_TX_DSC_CTS:
        merged_group_id = MergedTestGroups.HDTX_DSC_CTS
    elif fw_group == TestGroupId.HD_RX_DSC_CTS:
        merged_group_id = MergedTestGroups.HDRX_DSC_CTS
    elif fw_group == TestGroupId.HD_TX_CONTINUITY:
        merged_group_id = MergedTestGroups.HDTX_CONTINUITY
    elif fw_group == TestGroupId.HD_TX_CABLE_CHECK:
        merged_group_id = MergedTestGroups.HDTX_CABLE_CHECK
    else:
        merged_group_id = MergedTestGroups.Unknown
    return merged_group_id
