import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsInt, IsString, Min, Max, IsOptional, MinLength, MaxLength } from 'class-validator';
import { Type } from 'class-transformer';
import { VirtualAccountType } from '../../domain/value-objects/virtual-account-type.enum';

/**
 * 虚拟账户响应 DTO
 */
export class VirtualAccountResponseDto {
  @ApiProperty({ description: '账户ID' })
  id: string;

  @ApiProperty({ enum: VirtualAccountType, description: '账户类型' })
  accountType: VirtualAccountType;

  @ApiProperty({ description: '显示名称' })
  displayName: string;

  @ApiPropertyOptional({ description: '头像URL' })
  avatar: string | null;

  @ApiPropertyOptional({ description: '省份代码' })
  provinceCode: string | null;

  @ApiPropertyOptional({ description: '城市代码' })
  cityCode: string | null;

  @ApiPropertyOptional({ description: '最小分值' })
  minScore: number | null;

  @ApiPropertyOptional({ description: '最大分值' })
  maxScore: number | null;

  @ApiProperty({ description: '当前分值' })
  currentScore: number;

  @ApiProperty({ description: 'USDT 余额' })
  usdtBalance: number;

  @ApiProperty({ description: '算力余额' })
  hashpowerBalance: number;

  @ApiProperty({ description: '是否激活' })
  isActive: boolean;

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

/**
 * 批量生成虚拟账户请求 DTO
 */
export class GenerateVirtualAccountsDto {
  @ApiProperty({
    description: '生成数量',
    example: 10,
    minimum: 1,
    maximum: 50,
  })
  @IsInt()
  @Min(1)
  @Max(50)
  @Type(() => Number)
  count: number;

  @ApiProperty({
    description: '最小分值',
    example: 100,
    minimum: 0,
  })
  @IsInt()
  @Min(0)
  @Type(() => Number)
  minScore: number;

  @ApiProperty({
    description: '最大分值',
    example: 500,
    minimum: 0,
  })
  @IsInt()
  @Min(0)
  @Type(() => Number)
  maxScore: number;
}

/**
 * 更新虚拟账户请求 DTO
 */
export class UpdateVirtualAccountDto {
  @ApiPropertyOptional({ description: '显示名称', minLength: 1, maxLength: 100 })
  @IsOptional()
  @IsString()
  @MinLength(1)
  @MaxLength(100)
  displayName?: string;

  @ApiPropertyOptional({ description: '头像URL', maxLength: 255 })
  @IsOptional()
  @IsString()
  @MaxLength(255)
  avatar?: string;

  @ApiPropertyOptional({ description: '最小分值' })
  @IsOptional()
  @IsInt()
  @Min(0)
  @Type(() => Number)
  minScore?: number;

  @ApiPropertyOptional({ description: '最大分值' })
  @IsOptional()
  @IsInt()
  @Min(0)
  @Type(() => Number)
  maxScore?: number;
}
