import type { Vector3Dto } from "./contractsCommon";

export interface FactionDoctrineSnapshot {
  strategicPosture: string;
  expansionPosture: string;
  militaryPosture: string;
  economicPosture: string;
  desiredControlledSystems: number;
  desiredMilitaryPerFront: number;
  desiredMinersPerSystem: number;
  desiredTransportsPerSystem: number;
  desiredConstructors: number;
  reserveCreditsRatio: number;
  expansionBudgetRatio: number;
  warBudgetRatio: number;
  reserveMilitaryRatio: number;
  offensiveReadinessThreshold: number;
  supplySecurityBias: number;
  failureAversion: number;
  reinforcementLeadPerFront: number;
}

export interface FactionSystemMemorySnapshot {
  systemId: string;
  lastSeenAtUtc: string;
  lastEnemyShipCount: number;
  lastEnemyStationCount: number;
  controlledByFaction: boolean;
  lastRole?: string | null;
  frontierPressure: number;
  routeRisk: number;
  historicalShortagePressure: number;
  offensiveFailures: number;
  defensiveFailures: number;
  offensiveSuccesses: number;
  defensiveSuccesses: number;
  lastContestedAtUtc?: string | null;
  lastShortageAtUtc?: string | null;
}

export interface FactionCommodityMemorySnapshot {
  itemId: string;
  historicalShortageScore: number;
  historicalSurplusScore: number;
  lastObservedBacklog: number;
  updatedAtUtc: string;
  lastCriticalAtUtc?: string | null;
}

export interface FactionOutcomeRecordSnapshot {
  id: string;
  kind: string;
  summary: string;
  relatedCampaignId?: string | null;
  relatedObjectiveId?: string | null;
  occurredAtUtc: string;
}

export interface FactionMemorySnapshot {
  lastPlanCycle: number;
  updatedAtUtc: string;
  lastObservedShipsBuilt: number;
  lastObservedShipsLost: number;
  lastObservedCredits: number;
  knownSystemIds: string[];
  knownEnemyFactionIds: string[];
  systems: FactionSystemMemorySnapshot[];
  commodities: FactionCommodityMemorySnapshot[];
  recentOutcomes: FactionOutcomeRecordSnapshot[];
}

export interface FactionBudgetSnapshot {
  reservedCredits: number;
  expansionCredits: number;
  warCredits: number;
  reservedMilitaryAssets: number;
  reservedLogisticsAssets: number;
  reservedConstructionAssets: number;
}

export interface FactionCommoditySignalSnapshot {
  itemId: string;
  availableStock: number;
  onHand: number;
  productionRatePerSecond: number;
  committedProductionRatePerSecond: number;
  usageRatePerSecond: number;
  netRatePerSecond: number;
  projectedNetRatePerSecond: number;
  levelSeconds: number;
  level: string;
  projectedProductionRatePerSecond: number;
  buyBacklog: number;
  reservedForConstruction: number;
}

export interface FactionEconomicAssessmentSnapshot {
  planCycle: number;
  updatedAtUtc: string;
  militaryShipCount: number;
  minerShipCount: number;
  transportShipCount: number;
  constructorShipCount: number;
  controlledSystemCount: number;
  targetMilitaryShipCount: number;
  targetMinerShipCount: number;
  targetTransportShipCount: number;
  targetConstructorShipCount: number;
  hasShipyard: boolean;
  hasWarIndustrySupplyChain: boolean;
  primaryExpansionSiteId?: string | null;
  primaryExpansionSystemId?: string | null;
  replacementPressure: number;
  sustainmentScore: number;
  logisticsSecurityScore: number;
  criticalShortageCount: number;
  industrialBottleneckItemId?: string | null;
  commoditySignals: FactionCommoditySignalSnapshot[];
}

export interface FactionThreatSignalSnapshot {
  scopeId: string;
  scopeKind: string;
  enemyShipCount: number;
  enemyStationCount: number;
  enemyFactionId?: string | null;
}

export interface FactionThreatAssessmentSnapshot {
  planCycle: number;
  updatedAtUtc: string;
  enemyFactionCount: number;
  enemyShipCount: number;
  enemyStationCount: number;
  primaryThreatFactionId?: string | null;
  primaryThreatSystemId?: string | null;
  threatSignals: FactionThreatSignalSnapshot[];
}

export interface FactionTheaterSnapshot {
  id: string;
  kind: string;
  systemId: string;
  status: string;
  priority: number;
  supplyRisk: number;
  friendlyAssetValue: number;
  targetFactionId?: string | null;
  anchorEntityId?: string | null;
  anchorPosition?: Vector3Dto | null;
  updatedAtUtc: string;
  campaignIds: string[];
}

export interface FactionPlanStepSnapshot {
  id: string;
  kind: string;
  status: string;
  summary?: string | null;
  blockingReason?: string | null;
}

export interface FactionCampaignSnapshot {
  id: string;
  kind: string;
  status: string;
  priority: number;
  theaterId?: string | null;
  targetFactionId?: string | null;
  targetSystemId?: string | null;
  targetEntityId?: string | null;
  commodityId?: string | null;
  supportStationId?: string | null;
  currentStepIndex: number;
  createdAtUtc: string;
  updatedAtUtc: string;
  summary?: string | null;
  pauseReason?: string | null;
  continuationScore: number;
  supplyAdequacy: number;
  replacementPressure: number;
  failureCount: number;
  successCount: number;
  fleetCommanderId?: string | null;
  requiresReinforcement: boolean;
  steps: FactionPlanStepSnapshot[];
  objectiveIds: string[];
}

export interface FactionObjectiveSnapshot {
  id: string;
  campaignId: string;
  theaterId?: string | null;
  kind: string;
  delegationKind: string;
  behaviorKind: string;
  status: string;
  priority: number;
  commanderId?: string | null;
  homeSystemId?: string | null;
  homeStationId?: string | null;
  targetSystemId?: string | null;
  targetEntityId?: string | null;
  targetPosition?: Vector3Dto | null;
  itemId?: string | null;
  notes?: string | null;
  currentStepIndex: number;
  createdAtUtc: string;
  updatedAtUtc: string;
  useOrders: boolean;
  stagingOrderKind?: string | null;
  reinforcementLevel: number;
  steps: FactionPlanStepSnapshot[];
  reservedAssetIds: string[];
}

export interface FactionReservationSnapshot {
  id: string;
  objectiveId: string;
  campaignId?: string | null;
  assetKind: string;
  assetId: string;
  priority: number;
  createdAtUtc: string;
  updatedAtUtc: string;
}

export interface FactionProductionProgramSnapshot {
  id: string;
  kind: string;
  status: string;
  priority: number;
  campaignId?: string | null;
  commodityId?: string | null;
  moduleId?: string | null;
  shipKind?: string | null;
  targetSystemId?: string | null;
  targetCount: number;
  currentCount: number;
  notes?: string | null;
}

export interface FactionDecisionLogEntrySnapshot {
  id: string;
  kind: string;
  summary: string;
  relatedEntityId?: string | null;
  planCycle: number;
  occurredAtUtc: string;
}

export interface FactionStrategicStateSnapshot {
  planCycle: number;
  updatedAtUtc: string;
  status: string;
  budget: FactionBudgetSnapshot;
  economicAssessment: FactionEconomicAssessmentSnapshot;
  threatAssessment: FactionThreatAssessmentSnapshot;
  theaters: FactionTheaterSnapshot[];
  campaigns: FactionCampaignSnapshot[];
  objectives: FactionObjectiveSnapshot[];
  reservations: FactionReservationSnapshot[];
  productionPrograms: FactionProductionProgramSnapshot[];
}

export interface CommanderAssignmentSnapshot {
  commanderId: string;
  kind: string;
  behaviorKind: string;
  status: string;
  objectiveId?: string | null;
  campaignId?: string | null;
  theaterId?: string | null;
  parentCommanderId?: string | null;
  controlledEntityId?: string | null;
  priority: number;
  homeSystemId?: string | null;
  homeStationId?: string | null;
  targetSystemId?: string | null;
  targetEntityId?: string | null;
  targetPosition?: Vector3Dto | null;
  itemId?: string | null;
  notes?: string | null;
  updatedAtUtc?: string | null;
  activeObjectiveIds: string[];
  subordinateCommanderIds: string[];
}

export interface FactionSnapshot {
  id: string;
  label: string;
  color: string;
  credits: number;
  populationTotal: number;
  oreMined: number;
  goodsProduced: number;
  shipsBuilt: number;
  shipsLost: number;
  defaultPolicySetId?: string | null;
  doctrine: FactionDoctrineSnapshot;
  memory: FactionMemorySnapshot;
  strategicState: FactionStrategicStateSnapshot;
  decisionLog: FactionDecisionLogEntrySnapshot[];
  commanders: CommanderAssignmentSnapshot[];
}

export interface FactionDelta extends FactionSnapshot {}
