/**
 * 设备模拟模块类型定义
 *
 * @author czj
 * @date 2026-07-29
 */

/** 设备类型枚举 */
export type DeviceType = 'door' | 'paperless' | 'central' | 'client'

/** 设备类型标签映射 */
export const DEVICE_TYPE_LABELS: Record<DeviceType, string> = {
  door: '门口屏',
  paperless: '无纸化',
  central: '中控设备',
  client: '集控客户端',
}

/** 设备类型图标映射 */
export const DEVICE_TYPE_ICONS: Record<DeviceType, string> = {
  door: 'Monitor',
  paperless: 'Document',
  central: 'Setting',
  client: 'Computer',
}

/** 环境配置 */
export interface EnvConfig {
  id: string
  name: string
  brokerHost: string
  brokerPort: number
  username: string | null
  password: string | null
  topicPrefix: string
  topics: Record<string, string> | null
  useTls: boolean
  clientIdPrefix: string
  status: string
  lastConnectedAt: string | null
  createdAt: string
  updatedAt: string
}

/** 创建环境配置请求 */
export interface EnvConfigCreate {
  name: string
  brokerHost: string
  brokerPort?: number
  username?: string | null
  password?: string | null
  topicPrefix?: string
  topics?: Record<string, string> | null
  useTls?: boolean
  clientIdPrefix?: string
}

/** 更新环境配置请求 */
export interface EnvConfigUpdate {
  name?: string
  brokerHost?: string
  brokerPort?: number
  username?: string | null
  password?: string | null
  topicPrefix?: string
  topics?: Record<string, string> | null
  useTls?: boolean
  clientIdPrefix?: string
}

/** 模拟设备 */
export interface Simulator {
  id: string
  envConfigId: string
  deviceType: DeviceType
  deviceName: string
  deviceId: string
  status: string
  autoReconnect: boolean
  extraAttrs: Record<string, any> | null
  lastReportedAt: string | null
  totalReports: number
  createdAt: string
  updatedAt: string
}

/** 创建模拟设备请求 */
export interface SimulatorCreate {
  envConfigId: string
  deviceType: DeviceType
  deviceName: string
  deviceId: string
  autoReconnect?: boolean
  extraAttrs?: Record<string, any> | null
}

/** 更新模拟设备请求 */
export interface SimulatorUpdate {
  deviceName?: string
  autoReconnect?: boolean
  metadata?: Record<string, any> | null
}

/** 上报记录 */
export interface ReportLog {
  id: string
  deviceId: string
  topic: string
  payload: Record<string, any> | null
  direction: string
  status: string
  errorMessage: string | null
  createdAt: string
}

/** 手动上报请求 */
export interface ManualReportRequest {
  topic: string
  payload: Record<string, any>
}

/** 连接测试结果 */
export interface TestConnectionResponse {
  success: boolean
  message: string
  latencyMs: number | null
}

/** 环境配置列表响应 */
export interface EnvConfigListResponse {
  items: EnvConfig[]
  total: number
}

/** 模拟设备列表响应 */
export interface SimulatorListResponse {
  items: Simulator[]
  total: number
}

/** 上报记录列表响应 */
export interface ReportLogListResponse {
  items: ReportLog[]
  total: number
}