export interface OtaSettings {
  bandwidthKbps: number
  maxCar: number
  latencyEnabled: boolean
  rttThresholdMs: number
  overThreshold: 'skip' | 'confirm' | string
  backupPeriodMinutes: number
  backupExe: boolean
  newVersionName?: string | null
}

export interface OtaFileArtifact {
  hash: string
  path: string
  fileName: string
  time?: string
  size: number
}

export interface OtaTarget {
  packageId: string
  name?: string
  activatedAt: string
  components: Record<string, OtaFileArtifact>
}

export interface OtaPackageInfo {
  id: string
  sourceIp?: string
  createdAt: string
  totalBytes: number
  isTarget: boolean
  components: Record<string, OtaFileArtifact>
}

export interface OtaComponentVersion {
  version?: string
  time?: string
}

export interface OtaAppVersions {
  exe?: OtaComponentVersion
  dll?: OtaComponentVersion
  pdb?: OtaComponentVersion
}

export interface OtaVehicleRow {
  id: string
  name: string
  ip?: string
  state?: string
  group?: string
  reachable: boolean
  rttMs?: number | null
  medulla?: OtaAppVersions
  detour?: OtaAppVersions
  clumsy?: OtaAppVersions
  match?: Record<string, string>
}

export interface OtaJobStep {
  carId: string
  ip?: string
  component: string
  status: string
  error?: string
}

export interface OtaJob {
  id: string
  kind: string
  status: string
  createdAt: string
  finishedAt?: string
  createdBy?: string
  packageId?: string
  carIds: string[]
  components: string[]
  requireLatencyCheck: boolean
  doneSteps: number
  totalSteps: number
  steps: OtaJobStep[]
  message?: string
}

export const OTA_COMPONENT_KEYS = ['M.exe', 'M.dll', 'M.pdb', 'D.exe', 'C.exe', 'C.dll', 'C.pdb'] as const

export type OtaPane = 'vehicles' | 'packages' | 'jobs' | 'config' | 'custom' | 'settings'
