#pragma once

#include <optional>
#include <string>

#include "Formula.h"

// Region widths are in tiles (REQ-GW-REGIONS).
struct WorldRegions
{
    int asteroidWidth_tiles;
    int playerBufferWidth_tiles;
    int contestZoneWidth_tiles;
    int enemyBufferWidth_tiles;
};

// Asteroid expansion (REQ-EXP-UNLOCK, REQ-EXP-COST).
struct WorldExpansion
{
    int     columnsPerExpansion_tiles;
    Formula costBuildingBlocksFormula;  // cost in building blocks; x = expansions already purchased
};

// Push effects (REQ-PSH-*, REQ-WAV-BOSS-ADVANCE).
struct WorldPush
{
    int    pushExpandColumns_tiles;
    double bossAdvanceSeconds;  // boss countdown advanced by this much per push
};

// Wave scheduling (REQ-WAV-*).
struct WorldWaves
{
    Formula threatRateFormula;        // threat/s as a function of boss wave counter x
    double gapMinSeconds;
    double gapMaxSeconds;
    double spawnDurationSeconds;
    double bossCountdownSeconds;      // duration of each boss cycle (REQ-WAV-BOSS-COUNTDOWN)
    double bossThreatDurationSeconds; // boss budget = rate * this (REQ-WAV-BOSS-TRIGGER)
    double bossQuietBeforeSeconds;    // suppress normal waves this long before boss (REQ-WAV-QUIET)
    double bossQuietAfterSeconds;     // suppress normal waves this long after boss (REQ-WAV-QUIET)
};

// Ship target selection (claim-aware scoring).
struct WorldTargeting
{
    Formula targetScoreFormula;       // x = distance / max weapon range; higher = better
    Formula overclaimPenaltyFormula;  // x = competing claim count; factor in [0,1]
    double  hysteresis;               // fractional margin a challenger must beat the current target by
};

// Artifact win condition (REQ-WIN-ARTIFACT-COUNT, REQ-WIN-SCREEN).
struct WorldArtifacts
{
    Formula artifactChanceFormula;  // x = station level, result clamped to [0,1]
    int     artifactWinCount;
};

// View pan speed (REQ-UI-SCROLL-SPEED). Presentation-only; the simulation ignores these.
struct WorldScroll
{
    double panSpeedSlow_tps;        // tiles/s, used outside the contest zone
    double panSpeedFast_tps;        // tiles/s, used inside the contest zone
    int    panRampBandWidth_tiles;  // full width of the ramp band straddling each contest-zone boundary
};

struct WorldConfig
{
    int heightTiles;                    // REQ-GW-HEIGHT
    int refundPercentage;               // REQ-BLD-DECONSTRUCT
    double deconstructionTimeSeconds;   // REQ-BLD-DECON-QUEUE
    int startingBuildingBlocks;         // REQ-HQ-STARTING-BLOCKS
    double debrisDespawnSeconds;         // REQ-RES-DEBRIS-DROP
    double scrapPerThreat;              // REQ-RES-DEBRIS-DROP, REQ-THREAT-SCRAP (scrap dropped per unit threat)
    double tileSize_m;                  // metres per tile (REQ-GW-TILE-SIZE)
    double beltSpeed_tps;               // REQ-GW-BELT-SPEED (tiles/s, converted from m/s in config)
    int tunnelMaxDistance_tiles;        // REQ-BLD-TUNNEL-PAIR
    double departureIntervalSeconds;    // REQ-SHP-RALLY
    double orbitFactor;                 // REQ-SHP-ORBIT (multiplies tool range for orbit radius)
    double rallyOrbitRadius_tiles;      // REQ-SHP-ORBIT (fixed orbit radius around the rally point)

    // Optional hover-tooltip for the header artifact count display
    // (REQ-UI-ARTIFACTS-TOOLTIP). Presentation-only; the simulation ignores it.
    std::optional<std::string> artifactTooltip;

    WorldRegions regions;
    WorldExpansion expansion;
    WorldPush push;
    WorldWaves waves;
    WorldTargeting targeting;
    WorldArtifacts artifacts;
    WorldScroll scroll;
};
