import ctypes
from Grifo_E_1553lib.data_types.rdr_settings import RDROperationalSettings
from Grifo_E_1553lib.data_types.frequency import Frequency, BeaconDelayAndCode
from Grifo_E_1553lib.data_types.rf_channels_grouping_options import RFChannelsGroupingOptions
from Grifo_E_1553lib.data_types.param_value import ParamValue, ParamId
from Grifo_E_1553lib.data_types.radar_health_status_and_bit_report import RdrHealthStatusAndBitReport
from Grifo_E_1553lib.data_types.sw_release import SWRelease1, SWRelease2
from Grifo_E_1553lib.data_types.semicircle import Semicircle
from Grifo_E_1553lib.data_types.cursor_info import CursorXDisplayCoordAndQual, CursorYDisplayCoord ,CursorPositionLatitude, CursorPositionLongitude
# from Grifo_E_1553lib.data_types.enum_map import ENUM_MAP as em

# em.update({
#     "cursor_normal_slave_selector_tellback" :CrsNormalSlaveSelector,
#     "cursor_snowplough_command_tellback" :CrsSnowploughCommand
# })


class MsgRdrSettingsAndParametersTellback(ctypes.Structure):
    """
    A1: Radar Operational Setting and Parameter Transfer.

    Contains radar settings, frequency agility settings, beacon delay and code,
    gains, A/C identifier, date and time of mission, and parameter identifiers.
    """
    _pack_ = 1  # Forza l'allineamento a 1 byte
    _fields_ = [
        ("settings_tellback", RDROperationalSettings),
        ("frequency_tellback", Frequency),
        ("reserved1", BeaconDelayAndCode),
        ("rf_channels_grouping_options_tellback", RFChannelsGroupingOptions), 
        ("radar_health_status_and_bit_report_valid", RdrHealthStatusAndBitReport), 
        ("sw_release_1", SWRelease1), 
        ("sw_release_2", SWRelease2), 
        ("az_scan_centre", Semicircle), 
        ("el_scan_centre", Semicircle), 
        ("reserved2", ctypes.c_uint16), 
        ("reserved3", ctypes.c_uint16), 
        ("reserved4", ctypes.c_uint16), 
        ("param_id_tellback", ParamId),
        ("param_value_tellback", ParamValue),  # Placeholder
        ("cursor_x_display_coord_qual", CursorXDisplayCoordAndQual),
        ("cursor_y_display_coord", CursorYDisplayCoord),
        ("cursor_world_pos_range", ctypes.c_uint16),
        ("cursor_world_pos_azimuth", Semicircle),
        ("cursor_pos_latitude", CursorPositionLatitude),
        ("cursor_pos_longitude", CursorPositionLongitude),
        # ("param_value_2", ParamValue)   # Placeholder
    ]

    def __init__(self):
        super().__init__()
        # self.settings = RDROperationalSettings()
        # self.frequency = Frequency()
        # self.beacon = BeaconDelayAndCode()
        # self.rf_channels_grouping_options =RFChannelsGroupingOptions(0)  
        # self.ac_id = ctypes.c_uint16(0)  
        # self.date_of_mission = DateOfMission(0)  
        # self.time_of_mission = TimeOfMission(0)  
        # self.param_id = ParamId()
        # self.param_value_1 = ParamValue()  # Placeholder
        # self.param_value_2 = ParamValue()  # Placeholder





# typedef uint16_t avb_1553_word_t;

# typedef struct {
#   unsigned int wc: 5;
#   unsigned int sa: 5;
#   unsigned int tr: 1;
#   unsigned int rt: 5;
# } avb_1553_cw_structure_t;

# typedef union {
#   avb_1553_word_t raw;
#   avb_1553_cw_structure_t str;
# } avb_1553_cmd_word_t;

# typedef struct {
#     unsigned int tf: 1;
#     unsigned int bca: 1;
#     unsigned int sf: 1;
#     unsigned int busy: 1;
#     unsigned int brcs: 1;
#     unsigned int reserved: 3;
#     unsigned int sr: 1;
#     unsigned int instr: 1;
#     unsigned int me: 1;
#     unsigned int rt: 5;
# } avb_1553_sw_structure_t;

# typedef union {
#   avb_1553_word_t raw;
#   avb_1553_sw_structure_t str;
# } avb_1553_sts_word_t;