using System.Collections.Generic;

namespace GravCoin;

public sealed class PlayerSaveEnvelope
{
	public PlayerSaveData PlayerData { get; set; } = new();
	public string Hash { get; set; } = "";
}

public sealed class PlayerSaveData
{
	public const double StartingMoney = 1500.0;

	public int Version { get; set; } = 1;
	public bool HasMigrated { get; set; }
	public bool HasClaimedCloudCompensation { get; set; }
	public double LegacyMigrationReward { get; set; }

	public double Money { get; set; } = StartingMoney;
	public float CoinsHeld { get; set; }
	public float AvgBuyPrice { get; set; }
	public double TotalProfit { get; set; }
	public double ManualProfit { get; set; }
	public double BotProfit { get; set; }
	public int TotalTrades { get; set; }
	public int TotalBotsPurchased { get; set; }
	public bool HasCompletedTutorial { get; set; }
	public bool TutorialDone { get; set; }
	public int PermanentRank { get; set; }

	public double BestTradePnl { get; set; }
	public double WorstTradePnl { get; set; }
	public int BestStreak { get; set; }
	public double PeakNetWorth { get; set; }
	public int TotalPlaySec { get; set; }
	public int TradesWon { get; set; }
	public int PanicSellCount { get; set; }
	public long Achievements { get; set; }
	public int MineCount { get; set; }
	public string LastServerID { get; set; } = "";
	public long LastDisconnectTime { get; set; }

	public long LastSeenUnix { get; set; }
	public long LastBonusClaimTs { get; set; }
	public int DailyStreak { get; set; }
	public long DailyLastClaimTs { get; set; }
	public long DailyAnchorUnix { get; set; }
	public int DailyClockRollbackStrikes { get; set; }
	public string DailyRewardHash { get; set; } = "";
	public bool HasReceivedFirstWin { get; set; }
	public long WelcomeBoostEndUnix { get; set; }
	public bool HasGrantedStarterInfrastructure { get; set; }

	public UpgradeSaveData Upgrades { get; set; } = new();
	public List<BotSaveData> Bots { get; set; } = new();
	public InfrastructureSaveData Infrastructure { get; set; } = new();
	public MissionSaveData Missions { get; set; } = new();
	public HeritageSaveData Heritage { get; set; } = new();
}

public sealed class UpgradeSaveData
{
	public int GasLevel { get; set; }
	public int CoolingLevel { get; set; }
	public int UpgradeRevision { get; set; }
	public bool InsiderUnlocked { get; set; }
	public bool GpuUnlocked { get; set; }
	public bool SatelliteUnlocked { get; set; }
	public float InsiderLastUsedAt { get; set; } = -999_999f;
	public float LastInsiderTip { get; set; }
	public int HashLevel { get; set; }
	public int RewardLevel { get; set; }
}

public sealed class BotSaveData
{
	public int Tier { get; set; }
	public float FuelSeconds { get; set; }
	public float MaxFuelSeconds { get; set; }
	public bool IsActive { get; set; }
	public double NetProfit { get; set; }
	public int TradesWon { get; set; }
	public int TradesTotal { get; set; }
	public int Quality { get; set; }
	public double UserTradeAmount { get; set; }
	public float UserTakeProfitPct { get; set; }
	public float UserStopLossPct { get; set; }
	public float HeldCoins { get; set; }
	public double InvestedAmount { get; set; }
	public float EntryPrice { get; set; }
	public float PositionTP { get; set; }
	public float PositionSL { get; set; }
	public float PositionTargetPrice { get; set; }
	public float PositionHoldSeconds { get; set; }
	public int PositionCooldownTicks { get; set; }
}

public sealed class InfrastructureSaveData
{
	public int Revision { get; set; }
	public List<InfrastructureMachineSaveData> Machines { get; set; } = new();
}

public sealed class InfrastructureMachineSaveData
{
	public string Id { get; set; } = "";
	public int Owned { get; set; }
	public bool AutomationUnlocked { get; set; }
	public bool SpeedUpgradeUnlocked { get; set; }
	public bool ProfitUpgradeUnlocked { get; set; }
	public bool IsCycleRunning { get; set; }
	public float CycleElapsedSeconds { get; set; }
	public double LifetimeEarned { get; set; }
}

public sealed class MissionSaveData
{
	public int Revision { get; set; }
	public List<string> ClaimedMissionIds { get; set; } = new();
}

public sealed class HeritageSaveData
{
	public long TotalCoinsEarned { get; set; } // Lifetime total — never decreases
	public long Coins { get; set; }            // Spendable balance
	public int  Generation { get; set; }       // Number of heritage resets performed
	public int  StarterCapitalTier { get; set; } // 0=none, 1=+$500M, 2=+$100B, 3=+$50T, 4=+$10Qa
	public int  StarterInfraTier   { get; set; } // 0=none, 1=Pi+GPU, 2=Pi+GPU+Edge+Datacenter
	public bool InsiderBonus       { get; set; } // Start with Insider Tip unlocked
	public bool ExtendedWelcome    { get; set; } // Daily boost duration ×2
	public bool ZeroFeeBonus    { get; set; } // Start with max VPN (GasLevel 5)
	public bool TradeAmplifier  { get; set; } // Manual trade profits +20%
	public bool DailyFortune    { get; set; } // Daily rewards ×2
	public bool BotFarmBonus    { get; set; } // Start with CoolingLevel 2 (+2 bot slots)
}
