import ctypes
from .enums import (
    TargetHistory, GroundTargetRejectVel, MinDetectGroundVel, ALEBlanking,
    AltitudeBlock, PRFLookup
)

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

    # Bitfield accessors for history_level
    def get_history_level(self):
        return (self.raw >> 14) & 0x03

    def set_history_level(self, value):
        self.raw &= ~(0x03 << 14)  # Clear existing bits
        self.raw |= (value << 14)   # Set new bits

    # Bitfield accessors for sym_intensity
    def get_sym_intensity(self):
        return (self.raw >> 8) & 0x7F

    def set_sym_intensity(self, value):
        self.raw &= ~(0x7F << 8)
        self.raw |= (value << 8)

    # Bitfield accessors for ground_reject_vel_high
    def get_ground_reject_vel_high(self):
        return (self.raw >> 7) & 0x01

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

    # Bitfield accessors for min_detect_ground_radial_vel_high
    def get_min_detect_ground_radial_vel_high(self):
        return (self.raw >> 6) & 0x01

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

    # Bitfield accessors for ale_blanking_disable
    def get_ale_blanking_disable(self):
        return (self.raw >> 5) & 0x01

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

    # Bitfield accessors for altitude_block
    def get_altitude_block(self):
        return (self.raw >> 2) & 0x03

    def set_altitude_block(self, value):
        self.raw &= ~(0x03 << 2)
        self.raw |= (value << 2)

    # Bitfield accessors for prf_lookup_selection
    def get_prf_lookup_selection(self):
        return (self.raw >> 1) & 0x01

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

    # Bitfield accessors for sett_spare15 (spare bit)
    def get_sett_spare15(self):
        return (self.raw >> 0) & 0x01

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