from ..message_base import MessageBase
from ..constants import Subaddress
from ..fields import ScaledField

class MsgB3(MessageBase):
    """
    Message B3: TWS Targets 6, 7, 8
    
    ID: B3
    Direction: RT -> BC (Transmit)
    Subaddress: 13
    Rate: 6.25 Hz
    Document Ref: 7.2.3
    
    Contains Kinematic data for Targets 06, 07, 08.
    """
    SUBADDRESS = Subaddress.TX_TWS_6_7_8
    IS_TRANSMIT = True

    # ========================== TARGET 06 DATA ==========================
    # Words 01-09 (Indices 0-8)
    
    tgt_06_time_tag = ScaledField(word_index=0, start_bit=0, width=16, lsb_value=64.0)
    tgt_06_range = ScaledField(word_index=1, start_bit=0, width=16, lsb_value=8.0)
    
    tgt_06_pos_x = ScaledField(word_index=2, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_06_pos_y = ScaledField(word_index=3, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_06_pos_z = ScaledField(word_index=4, start_bit=0, width=16, lsb_value=2.5, signed=True)
    
    tgt_06_vel_mag = ScaledField(word_index=5, start_bit=0, width=16, lsb_value=0.0625)
    tgt_06_vel_x = ScaledField(word_index=6, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_06_vel_y = ScaledField(word_index=7, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_06_vel_z = ScaledField(word_index=8, start_bit=0, width=16, lsb_value=0.125, signed=True)

    # ========================== TARGET 07 DATA ==========================
    # Words 10-18 (Indices 9-17)

    tgt_07_time_tag = ScaledField(word_index=9, start_bit=0, width=16, lsb_value=64.0)
    tgt_07_range = ScaledField(word_index=10, start_bit=0, width=16, lsb_value=8.0)
    
    tgt_07_pos_x = ScaledField(word_index=11, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_07_pos_y = ScaledField(word_index=12, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_07_pos_z = ScaledField(word_index=13, start_bit=0, width=16, lsb_value=2.5, signed=True)
    
    tgt_07_vel_mag = ScaledField(word_index=14, start_bit=0, width=16, lsb_value=0.0625)
    tgt_07_vel_x = ScaledField(word_index=15, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_07_vel_y = ScaledField(word_index=16, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_07_vel_z = ScaledField(word_index=17, start_bit=0, width=16, lsb_value=0.125, signed=True)

    # ========================== TARGET 08 DATA ==========================
    # Words 19-27 (Indices 18-26)

    tgt_08_time_tag = ScaledField(word_index=18, start_bit=0, width=16, lsb_value=64.0)
    tgt_08_range = ScaledField(word_index=19, start_bit=0, width=16, lsb_value=8.0)
    
    tgt_08_pos_x = ScaledField(word_index=20, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_08_pos_y = ScaledField(word_index=21, start_bit=0, width=16, lsb_value=16.0, signed=True)
    tgt_08_pos_z = ScaledField(word_index=22, start_bit=0, width=16, lsb_value=2.5, signed=True)
    
    tgt_08_vel_mag = ScaledField(word_index=23, start_bit=0, width=16, lsb_value=0.0625)
    tgt_08_vel_x = ScaledField(word_index=24, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_08_vel_y = ScaledField(word_index=25, start_bit=0, width=16, lsb_value=0.125, signed=True)
    tgt_08_vel_z = ScaledField(word_index=26, start_bit=0, width=16, lsb_value=0.125, signed=True)