/*
 * MIT License
 * Author: Mark Allyn
 *
 * settings.h — all tunable compile-time constants for the radar exhibit.
 * Edit values here; no other source file should hard-code magic numbers.
 */

#pragma once
#include <array>

// ================================================================
// WINDOW AND LAYOUT
// ================================================================
constexpr int   WINDOW_WIDTH         = 1400;
constexpr int   WINDOW_HEIGHT        = 900;
constexpr int   LEFT_PANEL_WIDTH     = 380;

// Scope circle geometry (pixels, origin top-left for CPU code)
constexpr float SCOPE_CENTER_X       = 890.0f;   // (LEFT_PANEL_WIDTH + WINDOW_WIDTH)/2
constexpr float SCOPE_CENTER_Y_TOP   = 430.0f;   // from top of window
constexpr float SCOPE_CENTER_Y_GL    = 470.0f;   // WINDOW_HEIGHT - SCOPE_CENTER_Y_TOP
constexpr float SCOPE_RADIUS_PX      = 400.0f;

constexpr int   PHOSPHOR_FBO_SIZE    = 1024;      // texels per side for phosphor texture

// ================================================================
// PHOSPHOR — P7 (Marine PPI, ATC PPI, PAR)
// Sequence: blue flash → green persistence → yellow-green fade → dark
// ================================================================
constexpr float P7_DECAY_RATE        = 1.1513f;  // s^-1; <1% remains after 4 s

// Energy thresholds that define colour transitions in the display shader
constexpr float P7_THRESH_BLUE       = 0.82f;    // above this: blue strike
constexpr float P7_THRESH_GREEN      = 0.55f;    // above this: green persistence
constexpr float P7_THRESH_YELLOW_GR  = 0.22f;    // above this: yellow-green fade
constexpr float P7_THRESH_DARK       = 0.03f;    // below this: essentially black

// Colour anchors (RGB)
constexpr float P7_BLUE_R = 0.30f, P7_BLUE_G = 0.70f, P7_BLUE_B = 1.00f;
constexpr float P7_GREEN_R = 0.05f, P7_GREEN_G = 1.00f, P7_GREEN_B = 0.30f;
constexpr float P7_YGREE_R = 0.50f, P7_YGREE_G = 1.00f, P7_YGREE_B = 0.05f;
constexpr float P7_YELLW_R = 0.70f, P7_YELLW_G = 0.70f, P7_YELLW_B = 0.00f;

// Sweep background energy — gives the rotating beam its visible glow
constexpr float SWEEP_BACKGROUND_ENERGY   = 0.10f;
// Half-beamwidth used by sweep shader for target blob display (degrees)
constexpr float SWEEP_HALF_BEAM_DEG       = 1.0f;

// ================================================================
// PHOSPHOR — P1 (Marine A-Scope — stub for future)
// ================================================================
constexpr float P1_COLOR_R = 0.10f;
constexpr float P1_COLOR_G = 1.00f;
constexpr float P1_COLOR_B = 0.10f;

// ================================================================
// SWEEP TIMING
// ================================================================
constexpr float MARINE_PPI_SWEEP_PERIOD   = 4.0f;   // seconds per full rotation
constexpr float ATC_PPI_SWEEP_PERIOD      = 5.0f;
constexpr float PAR_SCAN_RATE_HZ          = 30.0f;
constexpr float CHAIN_HOME_PRF_HIGH_HZ    = 25.0f;
constexpr float CHAIN_HOME_PRF_LOW_HZ     = 12.5f;

// ================================================================
// GRATICULE — incandescent etched-glass colour
// ================================================================
constexpr float GRAT_R = 1.00f;
constexpr float GRAT_G = 0.85f;
constexpr float GRAT_B = 0.55f;

// Bearing ring geometry (fractions of SCOPE_RADIUS_PX)
constexpr float GRAT_INNER_RING_FRAC      = 0.915f;
constexpr float GRAT_OUTER_RING_FRAC      = 0.985f;
constexpr float GRAT_LABEL_RING_FRAC      = 1.020f;  // labels sit just outside outer ring
constexpr float GRAT_TICK_MAJOR_FRAC      = 0.055f;  // major tick length / scope radius
constexpr float GRAT_TICK_MINOR_FRAC      = 0.025f;  // minor tick length
constexpr int   GRAT_LABEL_INTERVAL_DEG   = 15;      // bearing label every N degrees
constexpr int   GRAT_SEGMENTS             = 360;     // circle tessellation segments

// ================================================================
// RANGE RINGS  (beam-painted; widths in normalised 0-1 scope space)
// ================================================================
constexpr float RING_WIDTH_NORM           = 0.005f;
constexpr float RING_BRIGHTNESS           = 0.72f;

// Marine PPI range steps (miles) and ring definitions
// Index:          0 (max 2 mi)    1 (max 4 mi)    2 (max 6 mi)
constexpr int   MARINE_RANGE_STEP_COUNT   = 3;
constexpr float MARINE_RANGE_STEPS[3]     = { 2.0f, 4.0f, 6.0f };
constexpr int   MARINE_RING_COUNT[3]      = { 2, 2, 2 };
// Ring distances in miles per max-range setting
constexpr float MARINE_RING_MILES[3][2]   = {
    { 1.0f, 2.0f },   // max 2 mi: rings at 1, 2
    { 2.0f, 4.0f },   // max 4 mi: rings at 2, 4
    { 4.0f, 6.0f }    // max 6 mi: rings at 4, 6
};

// ================================================================
// CURSOR
// ================================================================
constexpr float CURSOR_R                  = 1.0f;
constexpr float CURSOR_G                  = 1.0f;
constexpr float CURSOR_B                  = 0.0f;
constexpr float CURSOR_ARC_SPAN_DEG       = 10.0f;  // total arc width

// ================================================================
// BLOOM
// ================================================================
constexpr float BLOOM_LUMINANCE_THRESHOLD = 0.50f;
constexpr float BLOOM_BLUR_RADIUS_PX      = 4.0f;
constexpr float BLOOM_BLEND_STRENGTH      = 0.28f;
constexpr float BLOOM_SAMPLE_STEP_UV      = 2.5f / static_cast<float>(PHOSPHOR_FBO_SIZE);

// ================================================================
// RADAR PARAMETERS — MARINE (X-Band)
// ================================================================
constexpr float MARINE_FREQ_HZ            = 9.225e9f;
constexpr float MARINE_PEAK_POWER_W       = 30000.0f;
constexpr float MARINE_HORIZ_BW_DEG       = 0.5f;
constexpr float MARINE_VERT_BW_DEG        = 20.0f;
constexpr float MARINE_ANTENNA_HEIGHT_M   = 15.24f;   // 50 ft
constexpr float MARINE_SYSTEM_LOSS        = 10.0f;    // linear (10 dB)
constexpr float MARINE_ANTENNA_EFF        = 0.60f;
constexpr float MARINE_LAMBDA_M           = 0.03248f; // c / MARINE_FREQ_HZ
constexpr float MARINE_PLATFORM_LAT       = 48.74361f;
constexpr float MARINE_PLATFORM_LON       = -122.56467f;

// ================================================================
// RADAR PARAMETERS — ATC (S-Band) — stub constants
// ================================================================
constexpr float ATC_FREQ_HZ               = 3.0e9f;
constexpr float ATC_PEAK_POWER_W          = 25000.0f;
constexpr float ATC_HORIZ_BW_DEG          = 1.4f;
constexpr float ATC_VERT_BW_DEG           = 5.0f;
constexpr float ATC_ANTENNA_HEIGHT_M      = 15.24f;
constexpr float ATC_SYSTEM_LOSS           = 10.0f;
constexpr float ATC_ANTENNA_EFF           = 0.60f;
constexpr float ATC_LAMBDA_M              = 0.10f;
constexpr float ATC_PLATFORM_LAT          = 48.79269f;
constexpr float ATC_PLATFORM_LON          = -122.53753f;

// ================================================================
// RADAR EQUATION
// ================================================================
constexpr float MDS_WATTS                 = 1.0e-13f; // minimum detectable signal
constexpr float RADAR_DYNAMIC_RANGE_DB    = 60.0f;    // display dynamic range

// ================================================================
// DEFAULT TARGET DIMENSIONS (meters)
// ================================================================
constexpr float DEFAULT_GA_LENGTH_M       =  4.0f;
constexpr float DEFAULT_GA_WIDTH_M        =  1.0f;
constexpr float DEFAULT_COMM_LENGTH_M     = 30.0f;
constexpr float DEFAULT_COMM_WIDTH_M      =  5.0f;
constexpr float DEFAULT_AIS_LENGTH_M      = 20.0f;
constexpr float DEFAULT_AIS_BEAM_M        =  5.0f;
constexpr float DEFAULT_SIM_BOAT_LENGTH_M =  6.0f;
constexpr float DEFAULT_SIM_BOAT_BEAM_M   =  2.0f;

// ================================================================
// GENERAL OPERATOR CONTROLS — defaults, min/max  (all 0-1 unless noted)
// ================================================================
constexpr float DEFAULT_GAIN              = 0.70f;
constexpr float MIN_GAIN                  = 0.00f;
constexpr float MAX_GAIN                  = 1.00f;

constexpr float DEFAULT_RAIN_CLUTTER      = 0.00f;
constexpr float MIN_RAIN_CLUTTER          = 0.00f;
constexpr float MAX_RAIN_CLUTTER          = 1.00f;

constexpr float DEFAULT_WAVE_CLUTTER      = 0.00f;
constexpr float MIN_WAVE_CLUTTER          = 0.00f;
constexpr float MAX_WAVE_CLUTTER          = 1.00f;

constexpr float DEFAULT_INTENSITY         = 0.80f;
constexpr float DEFAULT_FOCUS             = 0.80f;
constexpr float DEFAULT_ASTIGMATISM       = 0.00f;
constexpr float DEFAULT_GRAT_INTENSITY    = 0.80f;

constexpr float KEY_GAIN_STEP             = 0.05f;
constexpr float KEY_CLUTTER_STEP          = 0.05f;

// ================================================================
// MARINE PPI SCOPE — startup defaults
// ================================================================
constexpr int   MARINE_PPI_DEFAULT_RANGE_IDX  = 1;    // index into MARINE_RANGE_STEPS (4 mi)
constexpr float MARINE_PPI_DEFAULT_CURSOR_BRG = 0.0f; // degrees True
constexpr float MARINE_PPI_DEFAULT_CURSOR_RNG = 2.0f; // miles
constexpr float MARINE_PPI_DEFAULT_BRG_OFFSET = 0.0f; // degrees
constexpr float MARINE_PPI_MIN_BRG_OFFSET     = -180.0f;
constexpr float MARINE_PPI_MAX_BRG_OFFSET     =  180.0f;

// ================================================================
// KEY-HOLD ACCELERATION
// ================================================================
constexpr float KEY_INITIAL_STEP_BRG      = 1.0f;    // degrees per first press
constexpr float KEY_INITIAL_STEP_RNG      = 0.10f;   // miles per first press
constexpr float KEY_HOLD_ACCEL_START_SEC  = 0.30f;   // seconds before acceleration
constexpr float KEY_HOLD_MAX_STEP_BRG     = 5.0f;    // max degrees/press when held
constexpr float KEY_HOLD_MAX_STEP_RNG     = 0.50f;   // max miles/press when held
constexpr float KEY_ACCEL_RATE            = 8.0f;    // multiplier rate (step *= 1 + rate*dt)

// ================================================================
// AUTO-ADVANCE TIMER
// ================================================================
constexpr float SCOPE_AUTO_ADVANCE_SEC    = 120.0f;

// ================================================================
// TARGET BUFFER
// ================================================================
constexpr int   MAX_TARGETS               = 32;

// ================================================================
// UNITS AND CONVERSION
// ================================================================
constexpr float FEET_TO_METERS            = 0.3048f;
constexpr float MILES_TO_METERS           = 1609.344f;
constexpr float KNOTS_TO_MPS              = 0.51444f;
constexpr float METERS_PER_DEGREE         = 111320.0f;

// ================================================================
// FONTS
// ================================================================
constexpr const char* FONT_PATH           = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf";
constexpr const char* FONT_FALLBACK       = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
constexpr int   LEFT_PANEL_FONT_SIZE      = 15;
constexpr int   CURSOR_READOUT_FONT_SIZE  = 17;
constexpr int   GRATICULE_LABEL_FONT_SIZE = 14;
constexpr int   GLYPH_ATLAS_SIZE          = 512;

// ================================================================
// TERRAIN — stub constants (terrain not used for Marine PPI)
// ================================================================
constexpr float TERRAIN_BBOX_LAT_MIN              = 48.50f;
constexpr float TERRAIN_BBOX_LAT_MAX              = 49.05f;
constexpr float TERRAIN_BBOX_LON_MIN              = -123.20f;
constexpr float TERRAIN_BBOX_LON_MAX              = -122.00f;
constexpr float TERRAIN_PROCESSED_CELL_DEG        = 0.0003f;
constexpr float TERRAIN_ROCK_THRESHOLD_M          = 150.0f;
constexpr float TERRAIN_ROCK_SLOPE_DEG            = 25.0f;
constexpr float TERRAIN_STRUCTURE_HEIGHT_M        = 2.0f;
constexpr float TERRAIN_SIGMA0_SOIL               = 0.010f;
constexpr float TERRAIN_SIGMA0_ROCK               = 0.032f;
constexpr float TERRAIN_SIGMA0_CONCRETE           = 0.100f;
constexpr float TERRAIN_SIGMA0_WATER_CALM         = 0.0003f;
constexpr float TERRAIN_SIGMA0_WATER_ROUGH        = 0.010f;
constexpr float TERRAIN_MARINE_CLUTTER_BRIGHTNESS = 0.60f;
constexpr bool  ATC_TERRAIN_CLUTTER_SUPPRESSED    = true;
constexpr bool  ATC_TERRAIN_SHADOW_ENABLED        = true;
constexpr int   TERRAIN_POLAR_BEARING_BINS        = 720;
constexpr int   TERRAIN_POLAR_RANGE_BINS          = 512;

// ================================================================
// BOAT PPI — stub constants (not used in Marine PPI)
// ================================================================
constexpr float BOAT_PEAK_POWER_W         = 6000.0f;
constexpr float BOAT_HORIZ_BW_DEG         = 1.9f;
constexpr float BOAT_VERT_BW_DEG          = 20.0f;
constexpr float BOAT_ANTENNA_HEIGHT_M     = 3.5f;
constexpr int   BOAT_RANGE_STEP_COUNT     = 3;
constexpr float BOAT_RANGE_STEPS[3]       = { 0.5f, 1.0f, 2.0f };
constexpr float BOAT_SUP_RCS_M2           = 0.20f;
constexpr float BOAT_KAYAK_RCS_M2         = 0.40f;
constexpr int   BOAT_RANDOM_KAYAK_COUNT   = 2;
constexpr float BOAT_WAYPOINT_ARRIVAL_M   = 50.0f;
constexpr float BOAT_HEADING_TURN_RATE    = 3.0f;  // deg/s
constexpr float BOAT_HEADUP_TOLERANCE_DEG = 5.0f;
constexpr int   BOAT_CLUTTER_MASK_COUNT   = 6;
constexpr float BOAT_MASK_SWITCH_THRESH_M = 500.0f;
constexpr float BOAT_HEADING_MARKER_FRAC  = 0.35f;
constexpr float BOAT_MARKER_DASH_PX       = 8.0f;
constexpr float BOAT_MARKER_GAP_PX        = 4.0f;
constexpr const char* BOAT_PATROL_ROUTE   = "data/patrol_route.json";

// ================================================================
// CHAIN HOME — stub constants
// ================================================================
constexpr float CHAIN_HOME_RCS_RESONANCE  = 3.0f;
