from ctypes import Structure, c_uint32


class SinkPanelReplayCapsStruct(Structure):
    class SuYGranularityStruct(Structure):
        _fields_ = [
            ("value_of_8", c_uint32, 1),
            ("value_of_10", c_uint32, 1),
            ("value_of_12", c_uint32, 1),
            ("value_of_14", c_uint32, 1),
            ("value_of_15", c_uint32, 1),
            ("value_of_16", c_uint32, 1),
            ("value_of_18", c_uint32, 1),
            ("value_of_20", c_uint32, 1),
            ("value_of_24", c_uint32, 1),
            ("value_of_30", c_uint32, 1),
            ("value_of_32", c_uint32, 1),
            ("value_of_36", c_uint32, 1),
            ("value_of_40", c_uint32, 1),
            ("value_of_48", c_uint32, 1),
            ("value_of_54", c_uint32, 1),
            ("value_of_64", c_uint32, 1),
            ("res",         c_uint32, 16),
        ]

    _fields_ = [
        ("pr_support", c_uint32, 1),
        ("selective_update_support", c_uint32, 1),
        ("early_transport_support", c_uint32, 1),
        ("res", c_uint32, 7),
        ("dsc_decode_func_support", c_uint32, 1),
        ("asynch_video_timing_support", c_uint32, 1),
        ("dsc_src_support", c_uint32, 1),
        ("granularity_needed", c_uint32, 1),
        ("y_gran_extended_supported", c_uint32, 1),
        ("link_off_supported", c_uint32, 1),
        ("res1", c_uint32, 16),
        ("pr_x_granularity", c_uint32),
        ("pr_y_granularity", c_uint32),
        ("su_y_granularity", SuYGranularityStruct)
    ]


class SinkPanelReplayStatusStruct(Structure):

    class PRStatusDebugStruct(Structure):
        _fields_ = [
            ("res", c_uint32, 8),
            ("psr_state", c_uint32, 1),
            ("res1", c_uint32, 1),
            ("crc_valid", c_uint32, 1),
            ("su_coordinate_valid", c_uint32, 1),
            ("res2", c_uint32, 20),
        ]

    _fields_ = [
        ("active_frame_crc_err", c_uint32, 1),
        ("rfb_storage_err", c_uint32, 1),
        ("vsc_sdp_err", c_uint32, 1),
        ("ass_dp_missing", c_uint32, 1),
        ("res", c_uint32, 12),
        ("self_status", c_uint32, 3),
        ("frame_locked", c_uint32, 2),
        ("frame_locked_status_valid", c_uint32, 1),
        ("res1", c_uint32, 10),
        ("debug", PRStatusDebugStruct)
    ]


class SinkPanelSelfRefreshCapsStruct(Structure):

    _fields_ = [
        ("psr_caps", c_uint32, 8),
        ("link_training_req_psr1", c_uint32, 1),
        ("psr_setup_time", c_uint32, 3),
        ("y_coor_psr2_su", c_uint32, 1),
        ("su_coordinates_shall_adhere", c_uint32, 1),
        ("no_update_aux_frame_sync", c_uint32, 1),
        ("res", c_uint32, 17),
        ("pr_x_granularity", c_uint32),
        ("pr_y_granularity", c_uint32),
    ]


class SinkPanelSelfRefreshStatusStruct(Structure):

    class PSRStatusDebugStruct(Structure):
        _fields_ = [
            ("min_frame_count_reentry", c_uint32, 1),
            ("last_actual_syn_latency", c_uint32, 1),
            ("psr_state", c_uint32, 1),
            ("update_rfb", c_uint32, 1),
            ("crc_valid", c_uint32, 1),
            ("su_valid", c_uint32, 1),
            ("first_scan_line_su", c_uint32, 1),
            ("last_scan_line_su", c_uint32, 1),
            ("y_coordinate_valid", c_uint32, 1),
            ("res", c_uint32, 17)
        ]

    _fields_ = [
        ("link_crc_err", c_uint32, 1),
        ("rfb_storage_err", c_uint32, 1),
        ("vsc_sdp_err", c_uint32, 1),
        ("res", c_uint32, 5),
        ("su_psr_caps_change", c_uint32, 1),
        ("res1", c_uint32, 1),
        ("self_refresh", c_uint32, 3),
        ("res2", c_uint32, 13),
        ("debugStatus", PSRStatusDebugStruct)
    ]
