from typing import TypeVar
from ctypes import Structure, Union, c_uint32


class FixedPdoSourceStruct(Structure):
    _fields_ = [
        ('max_current', c_uint32, 10),
        ('voltage', c_uint32, 10),
        ('peak_current', c_uint32, 2),
        ('', c_uint32, 3),
        ('dual_data_role', c_uint32, 1),
        ('usb_communication_capable', c_uint32, 1),
        ('externally_powered', c_uint32, 1),
        ('usb_suspend_supported', c_uint32, 1),
        ('dual_power_role_capable', c_uint32, 1),
        ('pdo_type', c_uint32, 2),
    ]


class FixedPdoSinkStruct(Structure):
    _fields_ = [
        ('oper_current', c_uint32, 10),
        ('voltage', c_uint32, 10),
        ('', c_uint32, 5),
        ('dual_data_role', c_uint32, 1),
        ('usb_communication_capable', c_uint32, 1),
        ('externally_powered', c_uint32, 1),
        ('usb_suspend_supported', c_uint32, 1),
        ('dual_power_role_capable', c_uint32, 1),
        ('pdo_type', c_uint32, 2),
    ]


class VariablePdoStruct(Structure):
    _fields_ = [
        ('max_current', c_uint32, 10),
        ('min_voltage', c_uint32, 10),
        ('max_voltage', c_uint32, 10),
        ('pdo_type', c_uint32, 2),
    ]


class BatteryPdoStruct(Structure):
    _fields_ = [
        ('max_power', c_uint32, 10),
        ('min_voltage', c_uint32, 10),
        ('max_voltage', c_uint32, 10),
        ('pdo_type', c_uint32, 2),
    ]


class PdoBriefInfo(Structure):
    _fields_ = [
        ('data', c_uint32, 30),
        ('pdo_type', c_uint32, 2)
    ]


class PdoUnion(Union):
    _fields_ = [
        ('data', c_uint32),
        ('brief_info', PdoBriefInfo),
        ('fixed_pdo_source', FixedPdoSourceStruct),
        ('fixed_pdo_sink', FixedPdoSinkStruct),
        ('variable_pdo', VariablePdoStruct),
        ('battery_pdo', BatteryPdoStruct)
    ]


PdoTypeStruct = TypeVar("PdoTypeStruct",
                        FixedPdoSinkStruct,
                        FixedPdoSourceStruct,
                        BatteryPdoStruct,
                        VariablePdoStruct)
