// API 响应类型 - 基础响应（无数据）
export interface BaseResponse {
  success: boolean
  errCode?: string
  errMessage?: string
}

// API 响应类型 - 单个数据响应
export interface IBaseResponse<T> {
  data?: T
  success: boolean
  errCode?: string
  errMessage?: string
}

// API 响应类型 - 分页列表响应
export interface IResponse<T> {
  success: boolean
  errCode?: string
  errMessage?: string
  data: {
    total: string
    list: T[]
  }
}

// 兼容旧代码 - ApiResponse 别名
export type ApiResponse<T = any> = IResponse<T>

// 分页参数（旧版，兼容）
export interface PageParams {
  pageNum: number
  pageSize: number
}

// 分页响应（旧版，兼容）
export interface PageResult<T = any> {
  total: number
  rows: T[]
}

// 分页请求参数（新版）
export interface PageRequest {
  page?: number
  size?: number
  keyword?: string
  enabled?: boolean | null
  sortBy?: string
  sortDir?: 'ASC' | 'DESC'
}

// 分页响应（新版）
export interface PageResponse<T> {
  list: T[]
  page: number
  size: number
  total: number
  totalPages: number
  hasNext: boolean
  hasPrevious: boolean
}

// 带分页的 API 响应
export interface IPageResponse<T> {
  success: boolean
  errCode?: string
  errMessage?: string
  data: PageResponse<T>
}

// 列表 API 响应（数组形式）
export interface IListResponse<T> {
  success: boolean
  errCode?: string
  errMessage?: string
  data: 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'
  lssId?: string
  model?: string
  rtspUrl?: string
  channelNo?: string
  remark?: string
  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'
  | 'UP'
  | 'DOWN'
  | 'LEFT'
  | 'RIGHT'
  | 'ZOOM_IN'
  | 'ZOOM_OUT'
  | 'STOP'

// PTZ 直接控制请求 (pan/tilt/zoom 方式)
export interface PTZControlRequest {
  pan?: number // 水平移动速度 -100 ~ 100
  tilt?: number // 垂直移动速度 -100 ~ 100
  zoom?: number // 缩放速度 -100 ~ 100
  channel?: number // 通道号（可选）
}

// Admin PTZ 控制请求
export interface AdminPTZRequest {
  id: number
  action: PTZAction
  speed?: number // 0.0 - 1.0
}

// 摄像头列表请求参数
export interface CameraListRequest extends PageRequest {
  machineId?: string
  lssId?: string
  status?: 'ONLINE' | 'OFFLINE'
  enabled?: boolean
}

// 机器列表请求参数
export interface MachineListRequest extends PageRequest {
  // 继承 PageRequest 的所有属性
}

// 兼容旧代码的类型别名
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
}

// ==================== LSS 节点相关类型 ====================

// LSS 节点状态
export type LssNodeStatus = 'ONLINE' | 'OFFLINE' | 'BUSY' | 'MAINTENANCE'

// LSS 节点信息 (新 API)
export interface LssNodeDTO {
  id: number
  lssId: string
  lssName: string
  machineId?: string
  address: string
  maxTasks: number
  currentTasks: number
  status: LssNodeStatus
  ffmpegVersion?: string
  systemInfo?: string
  enabled: boolean
  createdAt: string
  updatedAt: string
}

// LSS 节点列表请求参数
export interface LssNodeListRequest extends PageRequest {
  status?: LssNodeStatus
  machineId?: string
}

// LSS 节点统计信息
export interface LssNodeStatsDTO {
  total: number
  online: number
  offline: number
  busy: number
  maintenance: number
}

// 兼容旧代码 - LSS 心跳状态
export type LssHeartbeatStatus = 'active' | 'hold' | 'dead'

// 兼容旧代码 - LSS 信息 (旧 API)
export interface LssDTO {
  id: number
  lssId: string
  name: string
  address: string
  publicIp?: string
  heartbeat?: LssHeartbeatStatus
  heartbeatTime?: string
  ablyInfo?: string
}

// 兼容旧代码 - LSS 列表请求参数
export interface LssListRequest extends PageRequest {
  heartbeat?: LssHeartbeatStatus
}

// ==================== LiveStream 相关类型 ====================

// 推流方式
export type StreamMethod = 'ffmpeg' | 'obs' | 'gstreamer'

// LiveStream 状态
export type LiveStreamStatus = 'running' | 'stopped' | 'error'

// LiveStream 信息
export interface LiveStreamDTO {
  id: number
  streamSn: string
  name: string
  lssId?: number
  lssName?: string
  cameraId?: number
  cameraName?: string
  streamMethod: StreamMethod
  commandTemplate?: string
  status: LiveStreamStatus
  startedAt?: string
  stoppedAt?: string
  playUrl?: string
  createdAt: string
  updatedAt: string
}

// LiveStream 列表请求参数
export interface LiveStreamListRequest extends PageRequest {
  aoAgent?: string
  feature?: string
  status?: LiveStreamStatus
  lssId?: number
}

// LiveStream 创建请求
export interface LiveStreamAddRequest {
  name: string
  lssId?: number
  cameraId?: number
  streamMethod: StreamMethod
  commandTemplate?: string
}

// LiveStream 更新请求
export interface LiveStreamUpdateRequest {
  id: number
  name?: string
  lssId?: number
  cameraId?: number
  streamMethod?: StreamMethod
  commandTemplate?: string
}

// ==================== 摄像头厂家相关类型 ====================

// 摄像头厂家信息
export interface CameraVendorDTO {
  id: number
  code: string
  name: string
  description?: string
  logoUrl?: string
  supportOnvif: boolean
  supportPtz: boolean
  supportIsapi: boolean
  supportGb28181: boolean
  supportAudio: boolean
  resolution?: string
  defaultPort?: number
  defaultRtspPort?: number
  rtspUrlTemplate?: string
  enabled: boolean
  sortOrder?: number
  createdAt: string
  updatedAt: string
}

// 摄像头厂家列表请求参数
export interface CameraVendorListRequest extends PageRequest {
  // 继承 PageRequest 的所有属性
}

// 创建摄像头厂家请求
export interface CameraVendorAddRequest {
  code: string
  name: string
  description?: string
  logoUrl?: string
  supportOnvif?: boolean
  supportPtz?: boolean
  supportIsapi?: boolean
  supportGb28181?: boolean
  supportAudio?: boolean
  resolution?: string
  defaultPort?: number
  defaultRtspPort?: number
  rtspUrlTemplate?: string
  enabled?: boolean
  sortOrder?: number
}

// 更新摄像头厂家请求
export interface CameraVendorUpdateRequest {
  id: number
  code: string
  name: string
  description?: string
  logoUrl?: string
  supportOnvif?: boolean
  supportPtz?: boolean
  supportIsapi?: boolean
  supportGb28181?: boolean
  supportAudio?: boolean
  resolution?: string
  defaultPort?: number
  defaultRtspPort?: number
  rtspUrlTemplate?: string
  enabled?: boolean
  sortOrder?: number
}
