import ctypes
from .enums import TrackPriority
import Grifo_E_1553lib.data_types.enum_map as em
em.ENUM_MAP.update({
    "track_priority_target_05" : TrackPriority,
    "track_priority_target_06" : TrackPriority,
    "track_priority_target_07" : TrackPriority,
    "track_priority_target_08" : TrackPriority,
})

class _TrackPriority0508Str(ctypes.LittleEndianStructure):
    _pack_ = 1
    _fields_ = [
        
        ("track_priority_target_08", ctypes.c_uint16,4),
        ("track_priority_target_07", ctypes.c_uint16,4),
        ("track_priority_target_06", ctypes.c_uint16,4),
        ("track_priority_target_05", ctypes.c_uint16,4),
    ]
    
class TrackPriority0508(ctypes.Union):
    _fields_ = [
        ("raw", ctypes.c_uint16),
        ("str", _TrackPriority0508Str)
                ]

    def get_track_05_priority_field(self):
        return TrackPriority((self.raw >> 13) & 0x07)
    def set_track_05_priority_field(self, value):
        self.raw &= ~(0x07 << 13)
        self.raw |= (value << 13)

    def get_track_06_priority_field(self):
        return TrackPriority((self.raw >> 10) & 0x07)
    def set_track_06_priority_field(self, value):
        self.raw &= ~(0x07 << 10)
        self.raw |= (value << 10)

    def get_track_07_priority_field(self):
        return TrackPriority((self.raw >> 7) & 0x07)
    def set_track_07_priority_field(self, value):
        self.raw &= ~(0x07 << 7)
        self.raw |= (value << 7)

    def get_track_08_priority_field(self):
        return TrackPriority((self.raw >> 4) & 0x07)
    def set_track_08_priority_field(self, value):
        self.raw &= ~(0x07 << 4)
        self.raw |= (value << 4)

    def get_spare(self):
        return (self.raw >> 0) & 0x0F
    def set_spare(self, value):
        self.raw &= ~(0x0F << 0)
        self.raw |= (value << 0)