/**
 * Zulip账号关联数据传输对象
 *
 * 功能描述：
 * - 定义API请求和响应的数据结构和验证规则
 * - 提供统一的数据传输格式和类型约束
 * - 支持Swagger文档自动生成和API接口描述
 * - 实现数据验证、转换和序列化功能
 *
 * 职责分离：
 * - 数据结构定义：定义所有API相关的数据传输对象
 * - 验证规则：通过装饰器定义字段验证和约束规则
 * - 文档生成：提供Swagger API文档的元数据信息
 * - 类型安全：确保前后端数据交互的类型一致性
 *
 * 最近修改：
 * - 2026-01-07: 代码规范优化 - 完善文件头注释和移除未使用的导入
 * - 2026-01-07: 功能完善 - 优化DTO字段验证规则和文档描述
 * - 2025-01-07: 架构优化 - 统一数据传输对象的设计模式
 * - 2025-01-07: 初始创建 - 创建基础的DTO类和验证规则
 * - 2025-01-07: 功能实现 - 实现完整的请求响应DTO定义
 *
 * @author angjustinl
 * @version 1.1.0
 * @since 2025-01-07
 * @lastModified 2026-01-07
 */

import { IsString, IsNumber, IsEmail, IsEnum, IsOptional, IsBoolean } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

/**
 * 创建Zulip账号关联请求DTO
 */
export class CreateZulipAccountDto {
  @ApiProperty({ description: '游戏用户ID', example: '12345' })
  @IsString()
  gameUserId: string;

  @ApiProperty({ description: 'Zulip用户ID', example: 67890 })
  @IsNumber()
  zulipUserId: number;

  @ApiProperty({ description: 'Zulip邮箱地址', example: 'user@example.com' })
  @IsEmail()
  zulipEmail: string;

  @ApiProperty({ description: 'Zulip用户全名', example: '张三' })
  @IsString()
  zulipFullName: string;

  @ApiProperty({ description: '加密的Zulip API Key' })
  @IsString()
  zulipApiKeyEncrypted: string;

  @ApiPropertyOptional({
    description: '账号状态',
    enum: ['active', 'inactive', 'suspended', 'error'],
    default: 'active'
  })
  @IsOptional()
  @IsEnum(['active', 'inactive', 'suspended', 'error'])
  status?: 'active' | 'inactive' | 'suspended' | 'error';

  @ApiPropertyOptional({ description: '最后验证时间' })
  @IsOptional()
  lastVerifiedAt?: Date;
}

/**
 * 更新Zulip账号关联请求DTO
 */
export class UpdateZulipAccountDto {
  @ApiPropertyOptional({ description: 'Zulip用户全名', example: '李四' })
  @IsOptional()
  @IsString()
  zulipFullName?: string;

  @ApiPropertyOptional({ description: '加密的Zulip API Key' })
  @IsOptional()
  @IsString()
  zulipApiKeyEncrypted?: string;

  @ApiPropertyOptional({
    description: '账号状态',
    enum: ['active', 'inactive', 'suspended', 'error']
  })
  @IsOptional()
  @IsEnum(['active', 'inactive', 'suspended', 'error'])
  status?: 'active' | 'inactive' | 'suspended' | 'error';

  @ApiPropertyOptional({ description: '错误信息' })
  @IsOptional()
  @IsString()
  errorMessage?: string;

  @ApiPropertyOptional({ description: '重试次数', example: 0 })
  @IsOptional()
  @IsNumber()
  retryCount?: number;

  @ApiPropertyOptional({ description: '最后验证时间' })
  @IsOptional()
  lastVerifiedAt?: Date;
}

/**
 * Zulip账号关联查询DTO
 */
export class QueryZulipAccountDto {
  @ApiPropertyOptional({ description: '游戏用户ID', example: '12345' })
  @IsOptional()
  @IsString()
  gameUserId?: string;

  @ApiPropertyOptional({ description: 'Zulip用户ID', example: 67890 })
  @IsOptional()
  @IsNumber()
  zulipUserId?: number;

  @ApiPropertyOptional({ description: 'Zulip邮箱地址', example: 'user@example.com' })
  @IsOptional()
  @IsEmail()
  zulipEmail?: string;

  @ApiPropertyOptional({
    description: '账号状态',
    enum: ['active', 'inactive', 'suspended', 'error']
  })
  @IsOptional()
  @IsEnum(['active', 'inactive', 'suspended', 'error'])
  status?: 'active' | 'inactive' | 'suspended' | 'error';

  @ApiPropertyOptional({ description: '是否包含游戏用户信息', default: false })
  @IsOptional()
  @IsBoolean()
  includeGameUser?: boolean;
}

/**
 * Zulip账号关联响应DTO
 */
export class ZulipAccountResponseDto {
  @ApiProperty({ description: '关联记录ID', example: '1' })
  id: string;

  @ApiProperty({ description: '游戏用户ID', example: '12345' })
  gameUserId: string;

  @ApiProperty({ description: 'Zulip用户ID', example: 67890 })
  zulipUserId: number;

  @ApiProperty({ description: 'Zulip邮箱地址', example: 'user@example.com' })
  zulipEmail: string;

  @ApiProperty({ description: 'Zulip用户全名', example: '张三' })
  zulipFullName: string;

  @ApiProperty({
    description: '账号状态',
    enum: ['active', 'inactive', 'suspended', 'error']
  })
  status: 'active' | 'inactive' | 'suspended' | 'error';

  @ApiPropertyOptional({ description: '最后验证时间' })
  lastVerifiedAt?: string;

  @ApiPropertyOptional({ description: '最后同步时间' })
  lastSyncedAt?: string;

  @ApiPropertyOptional({ description: '错误信息' })
  errorMessage?: string;

  @ApiProperty({ description: '重试次数', example: 0 })
  retryCount: number;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;

  @ApiProperty({ description: '更新时间' })
  updatedAt: string;

  @ApiPropertyOptional({ description: '关联的游戏用户信息' })
  gameUser?: any;
}

/**
 * Zulip账号关联列表响应DTO
 */
export class ZulipAccountListResponseDto {
  @ApiProperty({ description: '账号关联列表', type: [ZulipAccountResponseDto] })
  accounts: ZulipAccountResponseDto[];

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

  @ApiProperty({ description: '当前页数量', example: 10 })
  count: number;
}

/**
 * 账号状态统计响应DTO
 */
export class ZulipAccountStatsResponseDto {
  @ApiProperty({ description: '正常状态账号数', example: 85 })
  active: number;

  @ApiProperty({ description: '未激活账号数', example: 10 })
  inactive: number;

  @ApiProperty({ description: '暂停状态账号数', example: 3 })
  suspended: number;

  @ApiProperty({ description: '错误状态账号数', example: 2 })
  error: number;

  @ApiProperty({ description: '总账号数', example: 100 })
  total: number;
}

/**
 * 批量操作请求DTO
 */
export class BatchUpdateStatusDto {
  @ApiProperty({ description: '账号ID列表', example: ['1', '2', '3'] })
  @IsString({ each: true })
  ids: string[];

  @ApiProperty({
    description: '新状态',
    enum: ['active', 'inactive', 'suspended', 'error']
  })
  @IsEnum(['active', 'inactive', 'suspended', 'error'])
  status: 'active' | 'inactive' | 'suspended' | 'error';
}

/**
 * 批量操作响应DTO
 */
export class BatchUpdateResponseDto {
  @ApiProperty({ description: '操作是否成功' })
  success: boolean;

  @ApiProperty({ description: '更新的记录数', example: 3 })
  updatedCount: number;

  @ApiPropertyOptional({ description: '错误信息' })
  error?: string;
}

/**
 * 账号验证请求DTO
 */
export class VerifyAccountDto {
  @ApiProperty({ description: '游戏用户ID', example: '12345' })
  @IsString()
  gameUserId: string;
}

/**
 * 账号验证响应DTO
 */
export class VerifyAccountResponseDto {
  @ApiProperty({ description: '验证是否成功' })
  success: boolean;

  @ApiProperty({ description: '账号是否有效' })
  isValid: boolean;

  @ApiPropertyOptional({ description: '验证时间' })
  verifiedAt?: string;

  @ApiPropertyOptional({ description: '错误信息' })
  error?: string;
}