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

export interface ShipSkillProfileSnapshot {
  navigation: number;
  trade: number;
  mining: number;
  combat: number;
  construction: number;
}

export interface ShipOrderSnapshot {
  id: string;
  kind: string;
  sourceKind: string;
  sourceId: string;
  status: string;
  priority: number;
  interruptCurrentPlan: boolean;
  createdAtUtc: string;
  label?: string | null;
  targetEntityId?: string | null;
  targetSystemId?: string | null;
  targetPosition?: Vector3Dto | null;
  sourceStationId?: string | null;
  destinationStationId?: string | null;
  itemId?: string | null;
  nodeId?: string | null;
  constructionSiteId?: string | null;
  moduleId?: string | null;
  waitSeconds: number;
  radius: number;
  maxSystemRange?: number | null;
  knownStationsOnly: boolean;
  failureReason?: string | null;
}

export interface ShipOrderTemplateSnapshot {
  kind: string;
  label?: string | null;
  targetEntityId?: string | null;
  targetSystemId?: string | null;
  targetPosition?: Vector3Dto | null;
  sourceStationId?: string | null;
  destinationStationId?: string | null;
  itemId?: string | null;
  nodeId?: string | null;
  constructionSiteId?: string | null;
  moduleId?: string | null;
  waitSeconds: number;
  radius: number;
  maxSystemRange?: number | null;
  knownStationsOnly: boolean;
}

export interface DefaultBehaviorSnapshot {
  kind: string;
  homeSystemId?: string | null;
  homeStationId?: string | null;
  areaSystemId?: string | null;
  targetEntityId?: string | null;
  itemId?: string | null;
  preferredNodeId?: string | null;
  preferredConstructionSiteId?: string | null;
  preferredModuleId?: string | null;
  targetPosition?: Vector3Dto | null;
  waitSeconds: number;
  radius: number;
  maxSystemRange: number;
  knownStationsOnly: boolean;
  patrolPoints: Vector3Dto[];
  patrolIndex: number;
  repeatOrders: ShipOrderTemplateSnapshot[];
  repeatIndex: number;
}

export interface ShipAssignmentSnapshot {
  commanderId: string;
  parentCommanderId?: string | null;
  kind: string;
  behaviorKind: string;
  status: string;
  objectiveId?: string | null;
  campaignId?: string | null;
  theaterId?: 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;
}

export interface ShipSubTaskSnapshot {
  id: string;
  kind: string;
  status: string;
  summary: string;
  targetEntityId?: string | null;
  targetSystemId?: string | null;
  targetNodeId?: string | null;
  targetPosition?: Vector3Dto | null;
  itemId?: string | null;
  moduleId?: string | null;
  threshold: number;
  amount: number;
  progress: number;
  elapsedSeconds: number;
  totalSeconds: number;
  blockingReason?: string | null;
}

export interface ShipPlanStepSnapshot {
  id: string;
  kind: string;
  status: string;
  summary: string;
  blockingReason?: string | null;
  currentSubTaskIndex: number;
  subTasks: ShipSubTaskSnapshot[];
}

export interface ShipPlanSnapshot {
  id: string;
  sourceKind: string;
  sourceId: string;
  kind: string;
  status: string;
  summary: string;
  currentStepIndex: number;
  createdAtUtc: string;
  updatedAtUtc: string;
  interruptReason?: string | null;
  failureReason?: string | null;
  steps: ShipPlanStepSnapshot[];
}

export interface ShipSnapshot {
  id: string;
  name: string;
  purpose: string;
  type: string;
  systemId: string;
  localPosition: Vector3Dto;
  localVelocity: Vector3Dto;
  targetLocalPosition: Vector3Dto;
  state: string;
  orderQueue: ShipOrderSnapshot[];
  defaultBehavior: DefaultBehaviorSnapshot;
  assignment?: ShipAssignmentSnapshot | null;
  skills: ShipSkillProfileSnapshot;
  activePlan?: ShipPlanSnapshot | null;
  currentStepId?: string | null;
  activeSubTasks: ShipSubTaskSnapshot[];
  controlSourceKind: string;
  controlSourceId?: string | null;
  controlReason?: string | null;
  lastReplanReason?: string | null;
  lastAccessFailureReason?: string | null;
  celestialId?: string | null;
  dockedStationId?: string | null;
  commanderId?: string | null;
  policySetId?: string | null;
  cargoCapacity: number;
  travelSpeed: number;
  travelSpeedUnit: string;
  inventory: InventoryEntry[];
  factionId: string;
  health: number;
  history: string[];
  spatialState: ShipSpatialStateSnapshot;
}

export interface ShipDelta extends ShipSnapshot {}

export interface ShipSpatialStateSnapshot {
  spaceLayer: string;
  currentSystemId: string;
  currentCelestialId?: string | null;
  localPosition?: Vector3Dto | null;
  systemPosition?: Vector3Dto | null;
  movementRegime: string;
  destinationNodeId?: string | null;
  transit?: ShipTransitSnapshot | null;
}

export interface ShipTransitSnapshot {
  regime: string;
  originNodeId?: string | null;
  destinationNodeId?: string | null;
  startedAtUtc?: string | null;
  arrivalDueAtUtc?: string | null;
  progress: number;
}
