from ctypes import Structure, c_uint32, c_uint16
from .cec_types import DeviceType


class DeviceTypePrivate(Structure):
    _fields_ = [
        ("reserved", c_uint32, 2),
        ("cecSwitch", c_uint32, 1),
        ('audioSystem', c_uint32, 1),
        ('pbDevice', c_uint32, 1),
        ('tuner', c_uint32, 1),
        ('recDev', c_uint32, 1),
        ('tv', c_uint32, 1),
    ]

    @property
    def value(self) -> int:
        return (self.reserved | self.cecSwitch << 2 | self.audioSystem << 3 | self.pbDevice << 4 | self.tuner << 5
                | self.recDev << 6 | self.tv << 7)

    @value.setter
    def value(self, dev_type: DeviceType):
        self.cecSwitch = dev_type.cec_switch
        self.audioSystem = dev_type.audio_system
        self.pbDevice = dev_type.pb_device
        self.tuner = dev_type.tuner
        self.recDev = dev_type.rec_dev
        self.tv = dev_type.tv


class CECStatusPrivate(Structure):
    _fields_ = [
        ("bufferOverflowed", c_uint32, 1)
    ]


class CECVersion(Structure):
    _fields_ = [
        ("minor", c_uint16),
        ("major", c_uint16)
    ]
