from ..message_base import MessageBase
from ..constants import Subaddress, DLTargetType
from ..fields import BitField, EnumField, ScaledField, ASCIIField

class MsgA8(MessageBase):
    """
    Message A8: Data Link Targets (Message #2)
    
    ID: A8
    Direction: BC -> RT (Receive)
    Subaddress: 08
    Rate: 6.25 Hz
    Document Ref: 7.1.8
    
    Contains:
    - Data for Targets 06-10
    """
    SUBADDRESS = Subaddress.RX_DATALINK_2
    IS_TRANSMIT = False
    RATE_HZ = 6.25

    # ========================== TARGET 06 ==========================
    tgt_06_pos_x = ScaledField(word_index=0, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_06_pos_y = ScaledField(word_index=1, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_06_track_angle = ScaledField(word_index=2, start_bit=0, width=16, lsb_value=3.05176e-5, signed=True)
    
    tgt_06_type = EnumField(word_index=3, start_bit=0, width=2, enum_cls=DLTargetType)
    tgt_06_velocity = ScaledField(word_index=3, start_bit=2, width=3, lsb_value=143.0)
    tgt_06_altitude = ScaledField(word_index=3, start_bit=5, width=7, lsb_value=1000.0)
    tgt_06_intercept_zone = BitField(word_index=3, start_bit=12, width=1)
    
    tgt_06_callsign_ab = ASCIIField(word_index=4)
    tgt_06_callsign_cd = ASCIIField(word_index=5)

    # ========================== TARGET 07 ==========================
    tgt_07_pos_x = ScaledField(word_index=6, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_07_pos_y = ScaledField(word_index=7, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_07_track_angle = ScaledField(word_index=8, start_bit=0, width=16, lsb_value=3.05176e-5, signed=True)
    
    tgt_07_type = EnumField(word_index=9, start_bit=0, width=2, enum_cls=DLTargetType)
    tgt_07_velocity = ScaledField(word_index=9, start_bit=2, width=3, lsb_value=143.0)
    tgt_07_altitude = ScaledField(word_index=9, start_bit=5, width=7, lsb_value=1000.0)
    tgt_07_intercept_zone = BitField(word_index=9, start_bit=12, width=1)
    
    tgt_07_callsign_ab = ASCIIField(word_index=10)
    tgt_07_callsign_cd = ASCIIField(word_index=11)

    # ========================== TARGET 08 ==========================
    tgt_08_pos_x = ScaledField(word_index=12, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_08_pos_y = ScaledField(word_index=13, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_08_track_angle = ScaledField(word_index=14, start_bit=0, width=16, lsb_value=3.05176e-5, signed=True)
    
    tgt_08_type = EnumField(word_index=15, start_bit=0, width=2, enum_cls=DLTargetType)
    tgt_08_velocity = ScaledField(word_index=15, start_bit=2, width=3, lsb_value=143.0)
    tgt_08_altitude = ScaledField(word_index=15, start_bit=5, width=7, lsb_value=1000.0)
    tgt_08_intercept_zone = BitField(word_index=15, start_bit=12, width=1)
    
    tgt_08_callsign_ab = ASCIIField(word_index=16)
    tgt_08_callsign_cd = ASCIIField(word_index=17)

    # ========================== TARGET 09 ==========================
    tgt_09_pos_x = ScaledField(word_index=18, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_09_pos_y = ScaledField(word_index=19, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_09_track_angle = ScaledField(word_index=20, start_bit=0, width=16, lsb_value=3.05176e-5, signed=True)
    
    tgt_09_type = EnumField(word_index=21, start_bit=0, width=2, enum_cls=DLTargetType)
    tgt_09_velocity = ScaledField(word_index=21, start_bit=2, width=3, lsb_value=143.0)
    tgt_09_altitude = ScaledField(word_index=21, start_bit=5, width=7, lsb_value=1000.0)
    tgt_09_intercept_zone = BitField(word_index=21, start_bit=12, width=1)
    
    tgt_09_callsign_ab = ASCIIField(word_index=22)
    tgt_09_callsign_cd = ASCIIField(word_index=23)

    # ========================== TARGET 10 ==========================
    tgt_10_pos_x = ScaledField(word_index=24, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_10_pos_y = ScaledField(word_index=25, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_10_track_angle = ScaledField(word_index=26, start_bit=0, width=16, lsb_value=3.05176e-5, signed=True)
    
    tgt_10_type = EnumField(word_index=27, start_bit=0, width=2, enum_cls=DLTargetType)
    tgt_10_velocity = ScaledField(word_index=27, start_bit=2, width=3, lsb_value=143.0)
    tgt_10_altitude = ScaledField(word_index=27, start_bit=5, width=7, lsb_value=1000.0)
    tgt_10_intercept_zone = BitField(word_index=27, start_bit=12, width=1)
    
    tgt_10_callsign_ab = ASCIIField(word_index=28)
    tgt_10_callsign_cd = ASCIIField(word_index=29)