namespace SpaceGame.Api.Factions.Contracts;

public sealed record FactionDoctrineSnapshot(
  string StrategicPosture,
  string ExpansionPosture,
  string MilitaryPosture,
  string EconomicPosture,
  int DesiredControlledSystems,
  int DesiredMilitaryPerFront,
  int DesiredMinersPerSystem,
  int DesiredTransportsPerSystem,
  int DesiredConstructors,
  float ReserveCreditsRatio,
  float ExpansionBudgetRatio,
  float WarBudgetRatio,
  float ReserveMilitaryRatio,
  float OffensiveReadinessThreshold,
  float SupplySecurityBias,
  float FailureAversion,
  int ReinforcementLeadPerFront);

public sealed record FactionSystemMemorySnapshot(
  string SystemId,
  DateTimeOffset LastSeenAtUtc,
  int LastEnemyShipCount,
  int LastEnemyStationCount,
  bool ControlledByFaction,
  string? LastRole,
  float FrontierPressure,
  float RouteRisk,
  float HistoricalShortagePressure,
  int OffensiveFailures,
  int DefensiveFailures,
  int OffensiveSuccesses,
  int DefensiveSuccesses,
  DateTimeOffset? LastContestedAtUtc,
  DateTimeOffset? LastShortageAtUtc);

public sealed record FactionCommodityMemorySnapshot(
  string ItemId,
  float HistoricalShortageScore,
  float HistoricalSurplusScore,
  float LastObservedBacklog,
  DateTimeOffset UpdatedAtUtc,
  DateTimeOffset? LastCriticalAtUtc);

public sealed record FactionOutcomeRecordSnapshot(
  string Id,
  string Kind,
  string Summary,
  string? RelatedCampaignId,
  string? RelatedObjectiveId,
  DateTimeOffset OccurredAtUtc);

public sealed record FactionMemorySnapshot(
  int LastPlanCycle,
  DateTimeOffset UpdatedAtUtc,
  int LastObservedShipsBuilt,
  int LastObservedShipsLost,
  float LastObservedCredits,
  IReadOnlyList<string> KnownSystemIds,
  IReadOnlyList<string> KnownEnemyFactionIds,
  IReadOnlyList<FactionSystemMemorySnapshot> Systems,
  IReadOnlyList<FactionCommodityMemorySnapshot> Commodities,
  IReadOnlyList<FactionOutcomeRecordSnapshot> RecentOutcomes);

public sealed record FactionBudgetSnapshot(
  float ReservedCredits,
  float ExpansionCredits,
  float WarCredits,
  int ReservedMilitaryAssets,
  int ReservedLogisticsAssets,
  int ReservedConstructionAssets);

public sealed record FactionCommoditySignalSnapshot(
  string ItemId,
  float AvailableStock,
  float OnHand,
  float ProductionRatePerSecond,
  float CommittedProductionRatePerSecond,
  float UsageRatePerSecond,
  float NetRatePerSecond,
  float ProjectedNetRatePerSecond,
  float LevelSeconds,
  string Level,
  float ProjectedProductionRatePerSecond,
  float BuyBacklog,
  float ReservedForConstruction);

public sealed record FactionEconomicAssessmentSnapshot(
  int PlanCycle,
  DateTimeOffset UpdatedAtUtc,
  int MilitaryShipCount,
  int MinerShipCount,
  int TransportShipCount,
  int ConstructorShipCount,
  int ControlledSystemCount,
  int TargetMilitaryShipCount,
  int TargetMinerShipCount,
  int TargetTransportShipCount,
  int TargetConstructorShipCount,
  bool HasShipyard,
  bool HasWarIndustrySupplyChain,
  string? PrimaryExpansionSiteId,
  string? PrimaryExpansionSystemId,
  float ReplacementPressure,
  float SustainmentScore,
  float LogisticsSecurityScore,
  int CriticalShortageCount,
  string? IndustrialBottleneckItemId,
  IReadOnlyList<FactionCommoditySignalSnapshot> CommoditySignals);

public sealed record FactionThreatSignalSnapshot(
  string ScopeId,
  string ScopeKind,
  int EnemyShipCount,
  int EnemyStationCount,
  string? EnemyFactionId);

public sealed record FactionThreatAssessmentSnapshot(
  int PlanCycle,
  DateTimeOffset UpdatedAtUtc,
  int EnemyFactionCount,
  int EnemyShipCount,
  int EnemyStationCount,
  string? PrimaryThreatFactionId,
  string? PrimaryThreatSystemId,
  IReadOnlyList<FactionThreatSignalSnapshot> ThreatSignals);

public sealed record FactionTheaterSnapshot(
  string Id,
  string Kind,
  string SystemId,
  string Status,
  float Priority,
  float SupplyRisk,
  float FriendlyAssetValue,
  string? TargetFactionId,
  string? AnchorEntityId,
  Vector3Dto? AnchorPosition,
  DateTimeOffset UpdatedAtUtc,
  IReadOnlyList<string> CampaignIds);

public sealed record FactionPlanStepSnapshot(
  string Id,
  string Kind,
  string Status,
  string? Summary,
  string? BlockingReason);

public sealed record FactionCampaignSnapshot(
  string Id,
  string Kind,
  string Status,
  float Priority,
  string? TheaterId,
  string? TargetFactionId,
  string? TargetSystemId,
  string? TargetEntityId,
  string? CommodityId,
  string? SupportStationId,
  int CurrentStepIndex,
  DateTimeOffset CreatedAtUtc,
  DateTimeOffset UpdatedAtUtc,
  string? Summary,
  string? PauseReason,
  float ContinuationScore,
  float SupplyAdequacy,
  float ReplacementPressure,
  int FailureCount,
  int SuccessCount,
  string? FleetCommanderId,
  bool RequiresReinforcement,
  IReadOnlyList<FactionPlanStepSnapshot> Steps,
  IReadOnlyList<string> ObjectiveIds);

public sealed record FactionObjectiveSnapshot(
  string Id,
  string CampaignId,
  string? TheaterId,
  string Kind,
  string DelegationKind,
  string BehaviorKind,
  string Status,
  float Priority,
  string? CommanderId,
  string? HomeSystemId,
  string? HomeStationId,
  string? TargetSystemId,
  string? TargetEntityId,
  Vector3Dto? TargetPosition,
  string? ItemId,
  string? Notes,
  int CurrentStepIndex,
  DateTimeOffset CreatedAtUtc,
  DateTimeOffset UpdatedAtUtc,
  bool UseOrders,
  string? StagingOrderKind,
  int ReinforcementLevel,
  IReadOnlyList<FactionPlanStepSnapshot> Steps,
  IReadOnlyList<string> ReservedAssetIds);

public sealed record FactionReservationSnapshot(
  string Id,
  string ObjectiveId,
  string? CampaignId,
  string AssetKind,
  string AssetId,
  float Priority,
  DateTimeOffset CreatedAtUtc,
  DateTimeOffset UpdatedAtUtc);

public sealed record FactionProductionProgramSnapshot(
  string Id,
  string Kind,
  string Status,
  float Priority,
  string? CampaignId,
  string? CommodityId,
  string? ModuleId,
  string? ShipKind,
  string? TargetSystemId,
  int TargetCount,
  int CurrentCount,
  string? Notes);

public sealed record FactionDecisionLogEntrySnapshot(
  string Id,
  string Kind,
  string Summary,
  string? RelatedEntityId,
  int PlanCycle,
  DateTimeOffset OccurredAtUtc);

public sealed record FactionStrategicStateSnapshot(
  int PlanCycle,
  DateTimeOffset UpdatedAtUtc,
  string Status,
  FactionBudgetSnapshot Budget,
  FactionEconomicAssessmentSnapshot EconomicAssessment,
  FactionThreatAssessmentSnapshot ThreatAssessment,
  IReadOnlyList<FactionTheaterSnapshot> Theaters,
  IReadOnlyList<FactionCampaignSnapshot> Campaigns,
  IReadOnlyList<FactionObjectiveSnapshot> Objectives,
  IReadOnlyList<FactionReservationSnapshot> Reservations,
  IReadOnlyList<FactionProductionProgramSnapshot> ProductionPrograms);

public sealed record CommanderAssignmentSnapshot(
  string CommanderId,
  string Kind,
  string BehaviorKind,
  string Status,
  string? ObjectiveId,
  string? CampaignId,
  string? TheaterId,
  string? ParentCommanderId,
  string? ControlledEntityId,
  float Priority,
  string? HomeSystemId,
  string? HomeStationId,
  string? TargetSystemId,
  string? TargetEntityId,
  Vector3Dto? TargetPosition,
  string? ItemId,
  string? Notes,
  DateTimeOffset? UpdatedAtUtc,
  IReadOnlyList<string> ActiveObjectiveIds,
  IReadOnlyList<string> SubordinateCommanderIds);

public sealed record FactionSnapshot(
  string Id,
  string Label,
  string Color,
  float Credits,
  float PopulationTotal,
  float OreMined,
  float GoodsProduced,
  int ShipsBuilt,
  int ShipsLost,
  string? DefaultPolicySetId,
  FactionDoctrineSnapshot Doctrine,
  FactionMemorySnapshot Memory,
  FactionStrategicStateSnapshot StrategicState,
  IReadOnlyList<FactionDecisionLogEntrySnapshot> DecisionLog,
  IReadOnlyList<CommanderAssignmentSnapshot> Commanders);

public sealed record FactionDelta(
  string Id,
  string Label,
  string Color,
  float Credits,
  float PopulationTotal,
  float OreMined,
  float GoodsProduced,
  int ShipsBuilt,
  int ShipsLost,
  string? DefaultPolicySetId,
  FactionDoctrineSnapshot Doctrine,
  FactionMemorySnapshot Memory,
  FactionStrategicStateSnapshot StrategicState,
  IReadOnlyList<FactionDecisionLogEntrySnapshot> DecisionLog,
  IReadOnlyList<CommanderAssignmentSnapshot> Commanders);
