import ctypes
from .enums import ParameterTransferEnabled, ReceiveTransmitSelector, ParamIdCode

class ParamId(ctypes.Structure):
    _fields_ = [("raw", ctypes.c_uint16)]

    def get_enable(self):
        return ParameterTransferEnabled((self.raw >> 15) & 0x01)

    def set_enable(self, value):
        self.raw &= ~(0x01 << 15)
        self.raw |= (value << 15)

    def get_tx(self):
        return ReceiveTransmitSelector((self.raw >> 14) & 0x01)

    def set_tx(self, value):
        self.raw &= ~(0x01 << 14)
        self.raw |= (value << 14)

    def get_num(self):
        return (self.raw >> 7) & 0xFF

    def set_num(self, value):
        self.raw &= ~(0xFF << 7)
        self.raw |= (value << 7)

    def get_spare(self):
        return (self.raw >> 0) & 0x3F

    def set_spare(self, value):
        self.raw &= ~(0x3F << 0)
        self.raw |= (value << 0)