from enum import IntEnum, unique

@unique
class Subaddress(IntEnum):
    """
    MIL-STD-1553 Subaddresses for GRIFO-F/TH (Ref. Tab. 3.11-1 & 3.11-2).
    """
    # RX Messages (BC -> RT)
    RX_SETTINGS    = 1   # Msg A1
    RX_COMMAND     = 2   # Msg A2
    RX_GRAPHIC     = 3   # Msg A3
    RX_NAV_DATA    = 4   # Msg A4
    RX_INU_HS      = 5   # Msg A5
    RX_NOT_USED    = 6   # Msg A6
    RX_DATALINK_1  = 7   # Msg A7
    RX_DATALINK_2  = 8   # Msg A8
    RX_RESERVED    = 9   # Msg A9
    
    # Mode Codes
    MODE_CODE_RX   = 0   # 00000
    MODE_CODE_TX   = 31  # 11111

    # TX Messages (RT -> BC)
    TX_TWS_1_2     = 11  # Msg B1
    TX_TWS_3_4_5   = 12  # Msg B2
    TX_TWS_6_7_8   = 13  # Msg B3
    TX_SPT         = 14  # Msg B4
    TX_TRACKED     = 15  # Msg B5
    TX_SETTING_TB  = 16  # Msg B6 (Tell-Back)
    TX_STATUS_TB   = 17  # Msg B7 (Tell-Back)
    TX_BIT_REPORT  = 18  # Msg B8
    TX_RES_SEARCH  = 19  # Msg B9
    TX_RES_MODE    = 20  # Msg B10
    TX_RES_DEBUG   = 21  # Msg B11
    TX_WRAPAROUND  = 30  # Data Wraparound


# --- A1: Radar Operational Setting Enums ---

class TargetHistory(IntEnum):
    """Ref. Tab. A1/01-A"""
    LEVEL_1 = 0
    LEVEL_2 = 1
    LEVEL_3 = 2
    LEVEL_4 = 3

class AltitudeBlock(IntEnum):
    """Ref. Tab. A1/01-F"""
    BTBK = 0    # Bottom Block
    TPBK = 1    # Top Block
    NORMAL = 2
    SPARE = 3

class FrequencyAgility(IntEnum):
    """Ref. Tab. A1/02-A"""
    FIXED = 0
    RANDOM = 1
    ADAPTIVE = 2
    SPARE = 3


# --- A2: Radar Operation Command Enums ---

class RadarMode(IntEnum):
    """Ref. Tab. A2/01-A and B7/01 (Master Mode)"""
    RWS = 0     # Range While Search
    VS = 1      # Velocity Search
    ACM = 2     # Air Combat Mode
    TWS = 3     # Track While Scan
    SPARE_04 = 4
    GM = 5      # Ground Map
    SEA1 = 6    # Sea Mode 1
    SEA2 = 7    # Sea Mode 2
    GMTI = 8    # Ground Moving Target Indicator
    BCN = 9     # Beacon
    AGR = 10    # Air to Ground Ranging
    TA = 11     # Terrain Avoidance
    WA = 12     # Weather Avoidance
    # 13-15 Spare/Reserved

class DesignationControl(IntEnum):
    """Ref. Tab. A2/01-B"""
    LOCK_ON_ENABLE = 0
    LOCK_ON_DTT = 1
    TRANSFER_HPT = 2
    REJECT = 3
    LOCK_ON_STT = 4
    DESIGNATE_TRACK = 5
    SPARE_06 = 6
    EXEC_SAR_SPOI = 7
    EXEC_SAR_CURSOR = 8
    NOT_VALID = 15

class RWSSubmode(IntEnum):
    """Ref. Tab. A2/02-A"""
    NAM = 0 # Normal Air Mode
    ASM = 1 # Adaptive Search Mode

class ACMSubmode(IntEnum):
    """Ref. Tab. A2/02-C"""
    BORESIGHT = 0
    NARROW = 1
    HUD = 2
    WIDE = 3
    VERTICAL = 4
    SLEWABLE = 5

class GMSubmode(IntEnum):
    """Ref. Tab. A2/02-D"""
    RBM = 0 # Real Beam Map
    DBS = 1 # Doppler Beam Sharpening

class RangeScale(IntEnum):
    """Ref. Tab. A2/02-G"""
    NM_80 = 0
    NM_40 = 1
    NM_20 = 2
    NM_10 = 3

class BarScan(IntEnum):
    """Ref. Tab. A2/02-G (Elevation Bars)"""
    BAR_1 = 0
    BAR_2 = 1
    SPARE = 2
    BAR_4 = 3

class AzimuthScan(IntEnum):
    """Ref. Tab. A2/02-I"""
    DEG_60 = 0 # +/- 60 (or 45)
    DEG_30 = 1 # +/- 30
    DEG_25 = 2 # +/- 25
    DEG_15 = 3 # +/- 15

class VelocityScale(IntEnum):
    """Ref. Tab. A2/02-I (VS Mode)"""
    KTS_2400 = 0
    KTS_1200 = 1
    
class IntBitStatus(IntEnum):
    """Ref. Tab. A2/01-C"""
    NORMAL = 0
    REQUEST = 1

class StandbyStatus(IntEnum):
    """Ref. Tab. A2/01-D"""
    OFF = 0
    ON = 1

class FreezeStatus(IntEnum):
    """Ref. Tab. A2/01-E"""
    NORMAL = 0
    FREEZE = 1

class SpotFunction(IntEnum):
    """Ref. Tab. A2/02-B"""
    NORMAL = 0
    SPOT = 1

class ExpandFunction(IntEnum):
    """Ref. Tab. A2/02-E"""
    NORMAL = 0
    EXPAND = 1
    # 2-3 Spare

class ZoomCommand(IntEnum):
    """Ref. Tab. A2/03-B"""
    NOT_ACTIVE = 0
    ZOOM_IN = 1
    ZOOM_OUT = 2
    SPARE = 3

class MapOrientation(IntEnum):
    """Ref. Tab. A2/03-C"""
    AC_NOSE = 0
    SLANT_CROSS_RANGE = 1
    # 2-3 Not Used
    
class BullsEyeSelect(IntEnum):
    """Ref. Tab. A3/01-B"""
    NONE = 0
    WAYPOINT_1 = 1
    WAYPOINT_2 = 2
    WAYPOINT_3 = 3

class WaypointType(IntEnum):
    """Ref. Tab. A3/04-B"""
    WAYPOINT = 0
    FLY_TO = 1

class WaypointQualifier(IntEnum):
    """Ref. Tab. A3/04-D"""
    LEFT = 0
    RIGHT = 1
    DTK = 2     # Desired Track
    MARK = 3

class InterceptMode(IntEnum):
    """Ref. Tab. A3/15-B"""
    REAR = 0
    ALL = 1

class LineStyle(IntEnum):
    """Ref. Tab. A3/15-C (Normal/Dashed)"""
    NORMAL = 0
    DASHED = 1

class SymbolState(IntEnum):
    """Ref. Tab. A3/21-B (Normal/Blink)"""
    NORMAL = 0
    BLINK = 1

class Identity(IntEnum):
    """Ref. Tab. A3/24-C/F"""
    FRIEND = 0
    FOE = 1
    
class CursorMode(IntEnum):
    """Ref. Tab. A4/01-M"""
    NORMAL = 0
    SLAVE = 1

class CursorSnowplough(IntEnum):
    """Ref. Tab. A4/01-O"""
    NORMAL = 0
    SNOWPLOUGH = 1

class CursorGhost(IntEnum):
    """Ref. Tab. A4/19-B"""
    NORMAL = 0
    GHOST = 1

class DTTEnable(IntEnum):
    """Ref. Tab. A4/19-C"""
    NORMAL = 0
    DTT_ENABLED = 1
    
class SAREnable(IntEnum):
    """SAR Enable flag (Ref. A4-related)"""
    NORMAL = 0
    SAR_ENABLED = 1
    
class DLTargetType(IntEnum):
    """Ref. Tab. A7/05-A"""
    TARGET = 0
    HIGH_PRIORITY_TARGET = 1
    MEMBER = 2
    HIGH_PRIORITY_MEMBER = 3
    
class TwsValidity(IntEnum):
    """Ref. Tab. B1/01-A"""
    INVALID = 0
    VALID = 1

class HptIdentifier(IntEnum):
    """Ref. Tab. B1/01-B"""
    TARGET_01 = 0
    TARGET_02 = 1
    TARGET_03 = 2
    TARGET_04 = 3
    TARGET_05 = 4
    TARGET_06 = 5
    TARGET_07 = 6
    TARGET_08 = 7
    NO_HPT = 15

class TrackPriority(IntEnum):
    """Ref. Tab. B1/02-A"""
    LEVEL_1 = 0 # Highest
    LEVEL_2 = 1
    LEVEL_3 = 2
    LEVEL_4 = 3
    LEVEL_5 = 4
    LEVEL_6 = 5
    LEVEL_7 = 6
    LEVEL_8 = 7 # Lowest

class TrackAccuracy(IntEnum):
    """Ref. Tab. B1/04-A"""
    LEVEL_0 = 0
    LEVEL_1 = 1
    LEVEL_2 = 2
    LEVEL_3 = 3
    
class NormFactorXY(IntEnum):
    """Ref. Tab. B4/02-E/F"""
    FACTOR_0 = 0 # Multiplier 0.5 ft
    FACTOR_1 = 1 # Multiplier 1 ft
    FACTOR_2 = 2 # Multiplier 2 ft
    FACTOR_3 = 3 # Multiplier 4 ft
    FACTOR_4 = 4 # Multiplier 8 ft
    FACTOR_5 = 5 # Multiplier 16 ft

class NormFactorZ(IntEnum):
    """Ref. Tab. B4/02-G"""
    FACTOR_0 = 0 # Multiplier 0.5 ft
    FACTOR_1 = 1 # Multiplier 1 ft
    FACTOR_2 = 2 # Multiplier 2 ft
    FACTOR_3 = 3 # Multiplier 4 ft
    
class RadarDesignationStatus(IntEnum):
    """Ref. Tab. B7/01-B"""
    STT = 0
    DTT = 1
    SAM = 2
    TWS_WITH_HPT = 3
    AGR_LOCK_ON = 4
    ACQUISITION_IN_PROGRESS = 5
    SAR = 7
    NOT_VALID = 15

class DegradedStatus(IntEnum):
    """Ref. Tab. B7/01-F"""
    NORMAL = 0
    DEGRADED = 1

class RfRadiationStatus(IntEnum):
    """Ref. Tab. B7/01-H"""
    ON = 0
    OFF = 1

class TransitionStatus(IntEnum):
    """Ref. Tab. B7/01-I"""
    NO_TRANSITION = 0
    IN_PROGRESS = 1

class AcquisitionResult(IntEnum):
    """Ref. Tab. B7/01-J"""
    UNSUCCESSFUL = 0
    SUCCESSFUL = 1

class SarFeasibility(IntEnum):
    """Ref. Tab. B7/03-D/E"""
    NOT_FEASIBLE = 0
    FEASIBLE = 1
    
class BitReportLabel(IntEnum):
    """Ref. Tab. B8/01-A"""
    POWER_UP_BIT = 0
    FAST_POWER_UP_BIT = 1
    INT_BIT = 2
    SWITCH_OFF = 3
    FAIL_ONSET = 4
    FAIL_STOP = 5
    # 6-7 Spare