// API 响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  timestamp?: number
  traceId?: string
}

// 分页参数
export interface PageParams {
  pageNum: number
  pageSize: number
}

// 分页响应
export interface PageResult<T = any> {
  total: number
  rows: T[]
}

// 登录参数
export interface LoginParams {
  username: string
  password: string
}

// 登录响应
export interface LoginResponse {
  token: string
  tokenType: string
  expiresIn: number
  refreshToken?: string
  admin: AdminInfo
}

// 管理员信息
export interface AdminInfo {
  id: number
  username: string
  nickname: string
  role: string
  lastLoginAt?: string
}

// 用户信息 (兼容旧代码)
export interface UserInfo {
  id: number
  username: string
  nickname: string
  role: string
  lastLoginAt?: string
}

// 通道信息 (Controller 用)
export interface ChannelDTO {
  channelId: string
  name: string
  rtspUrl: string
  defaultView: boolean
  status: 'ONLINE' | 'OFFLINE'
  cameraId: string
}

// 摄像头信息 (Controller 用)
export interface CameraDTO {
  cameraId: string
  name: string
  machineId: string
  status: 'ONLINE' | 'OFFLINE'
  capability: 'switch_only' | 'ptz_enabled'
  ptzSupported: boolean
  channels: ChannelDTO[]
}

// 通道详情 (Admin 用)
export interface ChannelInfoDTO {
  id: number
  channelId: string
  name: string
  rtspUrl: string
  defaultView: boolean
  status: 'ONLINE' | 'OFFLINE'
}

// 摄像头详情 (Admin 用)
export interface CameraInfoDTO {
  id: number
  cameraId: string
  name: string
  ip: string
  port: number
  username: string
  brand: string
  capability: 'switch_only' | 'ptz_enabled'
  status: 'ONLINE' | 'OFFLINE'
  machineId: string
  machineName: string
  enabled: boolean
  channels: ChannelInfoDTO[]
  createdAt: string
  updatedAt: string
}

// 添加摄像头请求
export interface CameraAddRequest {
  cameraId: string
  name: string
  ip: string
  port?: number
  username?: string
  password?: string
  brand?: string
  capability?: 'switch_only' | 'ptz_enabled'
  machineId?: string
  channels?: ChannelAddRequest[]
}

// 添加通道请求
export interface ChannelAddRequest {
  channelId: string
  name: string
  rtspUrl?: string
  defaultView?: boolean
}

// 更新摄像头请求
export interface CameraUpdateRequest {
  id: number
  name?: string
  ip?: string
  port?: number
  username?: string
  password?: string
  brand?: string
  capability?: 'switch_only' | 'ptz_enabled'
  machineId?: string
  enabled?: boolean
  channels?: ChannelUpdateRequest[]
}

// 更新通道请求
export interface ChannelUpdateRequest {
  id?: number
  channelId?: string
  name?: string
  rtspUrl?: string
  defaultView?: boolean
}

// 切换通道请求
export interface SwitchChannelRequest {
  machineId: string
  channelId: string
}

// 机器信息
export interface MachineDTO {
  id: number
  machineId: string
  name: string
  location: string
  description: string
  enabled: boolean
  cameraCount: number
  createdAt: string
  updatedAt: string
}

// 添加机器请求
export interface MachineAddRequest {
  machineId: string
  name: string
  location?: string
  description?: string
}

// 更新机器请求
export interface MachineUpdateRequest {
  id: number
  name?: string
  location?: string
  description?: string
  enabled?: boolean
}

// 仪表盘统计
export interface DashboardStatsDTO {
  machineTotal: number
  machineEnabled: number
  cameraTotal: number
  cameraOnline: number
  cameraOffline: number
  channelTotal: number
}

// 修改密码请求
export interface ChangePasswordRequest {
  oldPassword: string
  newPassword: string
}

// PTZ 动作类型
export type PTZAction = 'up' | 'down' | 'left' | 'right' | 'zoom_in' | 'zoom_out' | 'stop'

// 兼容旧代码的类型别名
export type CameraDevice = CameraInfoDTO
export type CameraChannel = ChannelInfoDTO

// 播放响应 (保留用于视频播放)
export interface PlayResponse {
  streamId: string
  flv: string
  ws_flv?: string
  rtsp?: string
  rtmp?: string
  hls?: string
  rtc?: string
  mediaServerId?: string
  deviceId?: string
  channelId?: string
}

// 录像记录 (保留用于视频回放)
export interface RecordItem {
  name?: string
  start: number
  end: number
  secrecy?: number
  type?: string
}
