import type {
  DevicePolicy,
  DeviceTelemetryItem,
  GroupUsePolicy,
} from '../../entities/device/model/types'

export type DeviceCondition = 'ok' | 'inspection'
export type DeviceConnection = 'online' | 'offline' | 'offlineDanger'

export type Device = {
  id: number
  factoryNumber: string
  model?: string
  imei: string
  imei2: string
  serialNumber?: string
  organisation?: string
  organisationId?: number
  policy?: DevicePolicy | null
  organisationPolicy?: GroupUsePolicy | null
  workTime: string | null
  employee: string | null
  condition: DeviceCondition
  connection: DeviceConnection
  connectionText: string
  registeredAt?: string
  lastLocationAt?: string
  lastLocationDate?: number
  battery?: number
  batteryMaxCapacity?: number
  telemetry?: DeviceTelemetryItem[]
  chargeCycles?: string
  totalWorkTime?: number | null
  mediumImpacts?: string
  overheats?: string
  image?: string
  location?: {
    lat: number
    lng: number
  }
  route?: {
    lat: number
    lng: number
    time?: string
  }[]
  permissions?: {
    wifi: boolean
    bluetooth: boolean
    gps: boolean
    camera: boolean
    sim: boolean
    speaker: boolean
    locked?: boolean
  }
  statusIcons: {
    gps: boolean
    wifi: boolean
    bluetooth: boolean
    lock: boolean
    camera: boolean
    sim: boolean
    sound: boolean
    kiosk: boolean
  }
}

export const conditionText: Record<DeviceCondition, string> = {
  ok: 'Исправно',
  inspection: 'Требует ТО',
}

export const connectionText: Record<DeviceConnection, string> = {
  online: 'В сети',
  offline: 'Не в сети',
  offlineDanger: 'Потерян',
}

export function getStatusClass(status: DeviceCondition | DeviceConnection) {
  if (status === 'ok' || status === 'online') return 'is-success'
  if (status === 'inspection' || status === 'offlineDanger') return 'is-danger'

  return 'is-muted'
}
