export type MachineStateCode = 'IDLE' | 'ENGINE_ON' | 'MOVING' | 'NO_DATA'

export type BeaconBindingStatus = 'BOUND' | 'UNBOUND'

export type Machine = {
  id: number
  name: string
  licensePlate: string
  type: string
  department: string
  description: string
  beaconId: number | null
  lastKnownState: MachineStateCode
  lastDataReceivedAt: string | null
  createdAt: string
  updatedAt: string
}

export type MachineState = {
  id: number
  code: MachineStateCode
  name: string
  description: string
}

export type MachineStateHistoryItem = {
  id: number
  machineId: number
  state: MachineStateCode
  startedAt: string
  endedAt: string | null
  durationSeconds: number | null
}

export type MachineSortField = 'ID' | 'Name' | 'Date'

export type MachineSortDirection = 'ASC' | 'DESC'

export type MachineDictionaryOption = {
  value: string
  label: string
  description?: string
}

export type MachineAnalyticsPeriod = 'today' | 'shift' | 'week' | 'month'

export type MachineAnalyticsDateRange = {
  dateFrom?: string
  dateTo?: string
}

export type MachineTelemetryInterval = {
  id: number
  machineId: number
  state: MachineStateCode
  startedAt: string
  endedAt: string
  durationSeconds: number
}

export type MachineDailyUsageStat = {
  machineId: number
  date: string
  movingSeconds: number
  engineOnSeconds: number
  idleSeconds: number
  noDataSeconds: number
  utilizationPercent: number
}

export type MachineUsageSummary = {
  machineId: number
  period: MachineAnalyticsPeriod
  movingSeconds: number
  engineOnSeconds: number
  idleSeconds: number
  noDataSeconds: number
  totalKnownSeconds: number
  utilizationPercent: number
}

export type MachineCalibrationPeriodPreset =
  'today' | 'yesterday' | 'week' | 'month' | 'custom'

export type MachineCalibrationPeriod = {
  preset: MachineCalibrationPeriodPreset
  periodStart: Date
  periodEnd: Date
}

export type MachineStateDefinition = {
  id: number
  name: string
  icon: string
  color: string
  description: string
  isSystem: boolean
  createdAt: string
  updatedAt: string
}

export type MachineCalibrationRule = {
  id: number
  machineId: number
  stateDefinitionId: number
  vibrationMin: number
  vibrationMax: number
  minDurationSeconds: number
  priority: number
  createdAt: string
  updatedAt: string
}

export type RecognizedMachineStateInterval = {
  id: number
  machineId: number
  stateDefinitionId: number | null
  startedAt: string
  endedAt: string
  durationSeconds: number
  vibrationMin: number | null
  vibrationMax: number | null
  vibrationAvg: number | null
  sampleCount: number
  isNoData: boolean
}
