/**
 * 聊天网关层响应 DTO 定义
 *
 * 功能描述：
 * - 定义聊天相关的响应数据传输对象
 * - 用于 HTTP 和 WebSocket 响应的数据结构
 * - 提供 Swagger API 文档的响应类型定义
 *
 * 最近修改：
 * - 2026-01-14: 代码规范优化 - 完善注释规范 (修改者: moyin)
 *
 * @author moyin
 * @version 1.0.1
 * @since 2026-01-14
 * @lastModified 2026-01-14
 */

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

/**
 * 聊天消息响应 DTO
 */
export class ChatMessageResponseDto {
  @ApiProperty({ description: '是否成功', example: true })
  success: boolean;

  @ApiPropertyOptional({ description: '消息ID', example: 'game_1234567890_user1' })
  messageId?: string;

  @ApiPropertyOptional({ description: '响应消息', example: '消息发送成功' })
  message?: string;

  @ApiPropertyOptional({ description: '错误信息', example: '消息内容不能为空' })
  error?: string;
}

/**
 * 聊天消息信息 DTO
 */
export class ChatMessageInfoDto {
  @ApiProperty({ description: '消息ID', example: 12345 })
  id: number;

  @ApiProperty({ description: '发送者用户名', example: 'Player_123' })
  sender: string;

  @ApiProperty({ description: '消息内容', example: '大家好！' })
  content: string;

  @ApiProperty({ description: '消息范围', example: 'local' })
  scope: string;

  @ApiProperty({ description: '地图ID', example: 'whale_port' })
  mapId: string;

  @ApiProperty({ description: '发送时间', example: '2026-01-14T14:30:00.000Z' })
  timestamp: string;

  @ApiProperty({ description: 'Zulip Stream 名称', example: 'Whale Port' })
  streamName: string;

  @ApiProperty({ description: 'Zulip Topic 名称', example: 'Game Chat' })
  topicName: string;
}

/**
 * 聊天历史响应 DTO
 */
export class ChatHistoryResponseDto {
  @ApiProperty({ description: '是否成功', example: true })
  success: boolean;

  @ApiProperty({ description: '消息列表', type: [ChatMessageInfoDto] })
  @ValidateNested({ each: true })
  @Type(() => ChatMessageInfoDto)
  messages: ChatMessageInfoDto[];

  @ApiProperty({ description: '总消息数', example: 150 })
  total: number;

  @ApiProperty({ description: '当前页消息数', example: 50 })
  count: number;

  @ApiPropertyOptional({ description: '错误信息', example: '获取消息历史失败' })
  error?: string;
}

/**
 * WebSocket 连接状态 DTO
 */
export class WebSocketStatusDto {
  @ApiProperty({ description: '总连接数', example: 25 })
  totalConnections: number;

  @ApiProperty({ description: '已认证连接数', example: 20 })
  authenticatedConnections: number;

  @ApiProperty({ description: '活跃会话数', example: 18 })
  activeSessions: number;

  @ApiProperty({ description: '各地图在线人数' })
  mapPlayerCounts: Record<string, number>;
}

/**
 * 系统状态响应 DTO
 */
export class SystemStatusResponseDto {
  @ApiProperty({ description: 'WebSocket 状态', type: WebSocketStatusDto })
  @ValidateNested()
  @Type(() => WebSocketStatusDto)
  websocket: WebSocketStatusDto;

  @ApiProperty({ description: 'Zulip 集成状态' })
  zulip: {
    serverConnected: boolean;
    serverVersion: string;
    botAccountActive: boolean;
    availableStreams: number;
    gameStreams: string[];
    recentMessageCount: number;
  };

  @ApiProperty({ description: '系统运行时间（秒）', example: 86400 })
  uptime: number;

  @ApiProperty({ description: '内存使用情况' })
  memory: {
    used: string;
    total: string;
    percentage: number;
  };
}
