namespace SpaceGame.Api.Geopolitics.Runtime;

public sealed class GeopoliticalStateRuntime
{
    public int Cycle { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<SystemRouteLinkRuntime> Routes { get; } = [];
    public DiplomaticStateRuntime Diplomacy { get; set; } = new();
    public TerritoryStateRuntime Territory { get; set; } = new();
    public EconomyRegionStateRuntime EconomyRegions { get; set; } = new();
    public string LastDeltaSignature { get; set; } = string.Empty;
}

public sealed class SystemRouteLinkRuntime
{
    public required string Id { get; init; }
    public required string SourceSystemId { get; set; }
    public required string DestinationSystemId { get; set; }
    public float Distance { get; set; }
    public bool IsPrimaryLane { get; set; } = true;
}

public sealed class DiplomaticStateRuntime
{
    public List<DiplomaticRelationRuntime> Relations { get; } = [];
    public List<TreatyRuntime> Treaties { get; } = [];
    public List<DiplomaticIncidentRuntime> Incidents { get; } = [];
    public List<BorderTensionRuntime> BorderTensions { get; } = [];
    public List<WarStateRuntime> Wars { get; } = [];
}

public sealed class DiplomaticRelationRuntime
{
    public required string Id { get; init; }
    public required string FactionAId { get; set; }
    public required string FactionBId { get; set; }
    public string Status { get; set; } = "active";
    public string Posture { get; set; } = "neutral";
    public float TrustScore { get; set; }
    public float TensionScore { get; set; }
    public float GrievanceScore { get; set; }
    public string TradeAccessPolicy { get; set; } = "restricted";
    public string MilitaryAccessPolicy { get; set; } = "restricted";
    public string? WarStateId { get; set; }
    public DateTimeOffset? CeasefireUntilUtc { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> ActiveTreatyIds { get; } = [];
    public List<string> ActiveIncidentIds { get; } = [];
}

public sealed class TreatyRuntime
{
    public required string Id { get; init; }
    public required string Kind { get; set; }
    public string Status { get; set; } = "active";
    public string TradeAccessPolicy { get; set; } = "restricted";
    public string MilitaryAccessPolicy { get; set; } = "restricted";
    public string? Summary { get; set; }
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> FactionIds { get; } = [];
}

public sealed class DiplomaticIncidentRuntime
{
    public required string Id { get; init; }
    public required string Kind { get; set; }
    public string Status { get; set; } = "active";
    public required string SourceFactionId { get; set; }
    public required string TargetFactionId { get; set; }
    public string? SystemId { get; set; }
    public string? BorderEdgeId { get; set; }
    public required string Summary { get; set; }
    public float Severity { get; set; }
    public float EscalationScore { get; set; }
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset LastObservedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class BorderTensionRuntime
{
    public required string Id { get; init; }
    public required string RelationId { get; set; }
    public required string BorderEdgeId { get; set; }
    public required string FactionAId { get; set; }
    public required string FactionBId { get; set; }
    public string Status { get; set; } = "active";
    public float TensionScore { get; set; }
    public float IncidentScore { get; set; }
    public float MilitaryPressure { get; set; }
    public float AccessFriction { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> SystemIds { get; } = [];
}

public sealed class WarStateRuntime
{
    public required string Id { get; init; }
    public required string RelationId { get; set; }
    public required string FactionAId { get; set; }
    public required string FactionBId { get; set; }
    public string Status { get; set; } = "active";
    public string WarGoal { get; set; } = "territorial-pressure";
    public float EscalationScore { get; set; }
    public DateTimeOffset StartedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset? CeasefireUntilUtc { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> ActiveFrontLineIds { get; } = [];
}

public sealed class TerritoryStateRuntime
{
    public List<TerritoryClaimRuntime> Claims { get; } = [];
    public List<TerritoryInfluenceRuntime> Influences { get; } = [];
    public List<TerritoryControlStateRuntime> ControlStates { get; } = [];
    public List<SectorStrategicProfileRuntime> StrategicProfiles { get; } = [];
    public List<BorderEdgeRuntime> BorderEdges { get; } = [];
    public List<FrontLineRuntime> FrontLines { get; } = [];
    public List<TerritoryZoneRuntime> Zones { get; } = [];
    public List<TerritoryPressureRuntime> Pressures { get; } = [];
}

public sealed class TerritoryClaimRuntime
{
    public required string Id { get; init; }
    public string? SourceClaimId { get; set; }
    public required string FactionId { get; set; }
    public required string SystemId { get; set; }
    public required string CelestialId { get; set; }
    public string Status { get; set; } = "active";
    public string ClaimKind { get; set; } = "infrastructure";
    public float ClaimStrength { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class TerritoryInfluenceRuntime
{
    public required string Id { get; init; }
    public required string SystemId { get; set; }
    public required string FactionId { get; set; }
    public float ClaimStrength { get; set; }
    public float AssetStrength { get; set; }
    public float LogisticsStrength { get; set; }
    public float TotalInfluence { get; set; }
    public bool IsContesting { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class TerritoryControlStateRuntime
{
    public required string SystemId { get; init; }
    public string? ControllerFactionId { get; set; }
    public string? PrimaryClaimantFactionId { get; set; }
    public string ControlKind { get; set; } = "unclaimed";
    public bool IsContested { get; set; }
    public float ControlScore { get; set; }
    public float StrategicValue { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> ClaimantFactionIds { get; } = [];
    public List<string> InfluencingFactionIds { get; } = [];
}

public sealed class SectorStrategicProfileRuntime
{
    public required string SystemId { get; init; }
    public string? ControllerFactionId { get; set; }
    public string ZoneKind { get; set; } = "unclaimed";
    public bool IsContested { get; set; }
    public float StrategicValue { get; set; }
    public float SecurityRating { get; set; }
    public float TerritorialPressure { get; set; }
    public float LogisticsValue { get; set; }
    public string? EconomicRegionId { get; set; }
    public string? FrontLineId { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class BorderEdgeRuntime
{
    public required string Id { get; init; }
    public required string SourceSystemId { get; set; }
    public required string DestinationSystemId { get; set; }
    public string? SourceFactionId { get; set; }
    public string? DestinationFactionId { get; set; }
    public bool IsContested { get; set; }
    public string? RelationId { get; set; }
    public float TensionScore { get; set; }
    public float CorridorImportance { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class FrontLineRuntime
{
    public required string Id { get; init; }
    public string Kind { get; set; } = "border-front";
    public string Status { get; set; } = "active";
    public string? AnchorSystemId { get; set; }
    public float PressureScore { get; set; }
    public float SupplyRisk { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> FactionIds { get; } = [];
    public List<string> SystemIds { get; } = [];
    public List<string> BorderEdgeIds { get; } = [];
}

public sealed class TerritoryZoneRuntime
{
    public required string Id { get; init; }
    public required string SystemId { get; set; }
    public string? FactionId { get; set; }
    public string Kind { get; set; } = "unclaimed";
    public string Status { get; set; } = "active";
    public string? Reason { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class TerritoryPressureRuntime
{
    public required string Id { get; init; }
    public required string SystemId { get; set; }
    public string? FactionId { get; set; }
    public string Kind { get; set; } = "border-pressure";
    public float PressureScore { get; set; }
    public float SecurityScore { get; set; }
    public float HostileInfluence { get; set; }
    public float CorridorRisk { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class EconomyRegionStateRuntime
{
    public List<EconomicRegionRuntime> Regions { get; } = [];
    public List<SupplyNetworkRuntime> SupplyNetworks { get; } = [];
    public List<LogisticsCorridorRuntime> Corridors { get; } = [];
    public List<RegionalProductionProfileRuntime> ProductionProfiles { get; } = [];
    public List<RegionalTradeBalanceRuntime> TradeBalances { get; } = [];
    public List<RegionalBottleneckRuntime> Bottlenecks { get; } = [];
    public List<RegionalSecurityAssessmentRuntime> SecurityAssessments { get; } = [];
    public List<RegionalEconomicAssessmentRuntime> EconomicAssessments { get; } = [];
}

public sealed class EconomicRegionRuntime
{
    public required string Id { get; init; }
    public string? FactionId { get; set; }
    public required string Label { get; set; }
    public string Kind { get; set; } = "balanced-region";
    public string Status { get; set; } = "active";
    public required string CoreSystemId { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> SystemIds { get; } = [];
    public List<string> StationIds { get; } = [];
    public List<string> FrontLineIds { get; } = [];
    public List<string> CorridorIds { get; } = [];
}

public sealed class SupplyNetworkRuntime
{
    public required string Id { get; init; }
    public required string RegionId { get; set; }
    public float ThroughputScore { get; set; }
    public float RiskScore { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> StationIds { get; } = [];
    public List<string> ProducerItemIds { get; } = [];
    public List<string> ConsumerItemIds { get; } = [];
    public List<string> ConstructionItemIds { get; } = [];
}

public sealed class LogisticsCorridorRuntime
{
    public required string Id { get; init; }
    public string? FactionId { get; set; }
    public string Kind { get; set; } = "supply-corridor";
    public string Status { get; set; } = "active";
    public float RiskScore { get; set; }
    public float ThroughputScore { get; set; }
    public string AccessState { get; set; } = "restricted";
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> SystemPathIds { get; } = [];
    public List<string> RegionIds { get; } = [];
    public List<string> BorderEdgeIds { get; } = [];
}

public sealed class RegionalProductionProfileRuntime
{
    public required string RegionId { get; set; }
    public string PrimaryIndustry { get; set; } = "mixed";
    public int ShipyardCount { get; set; }
    public int StationCount { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
    public List<string> ProducedItemIds { get; } = [];
    public List<string> ScarceItemIds { get; } = [];
}

public sealed class RegionalTradeBalanceRuntime
{
    public required string RegionId { get; set; }
    public int ImportsRequiredCount { get; set; }
    public int ExportsSurplusCount { get; set; }
    public int CriticalShortageCount { get; set; }
    public float NetTradeScore { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class RegionalBottleneckRuntime
{
    public required string Id { get; init; }
    public required string RegionId { get; set; }
    public required string ItemId { get; set; }
    public string Cause { get; set; } = "regional-shortage";
    public string Status { get; set; } = "active";
    public float Severity { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class RegionalSecurityAssessmentRuntime
{
    public required string RegionId { get; set; }
    public float SupplyRisk { get; set; }
    public float BorderPressure { get; set; }
    public int ActiveWarCount { get; set; }
    public int HostileRelationCount { get; set; }
    public float AccessFriction { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class RegionalEconomicAssessmentRuntime
{
    public required string RegionId { get; set; }
    public float SustainmentScore { get; set; }
    public float ProductionDepth { get; set; }
    public float ConstructionPressure { get; set; }
    public float CorridorDependency { get; set; }
    public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}
