import {
  IsString,
  IsNotEmpty,
  Matches,
  Length,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

// ============ Request DTOs ============

export class GetKycStatusDto {
  // 无需参数，从 JWT 获取用户信息
}

export class VerifyPhoneForKycDto {
  @ApiProperty({
    example: '123456',
    description: '6位短信验证码',
  })
  @IsString()
  @IsNotEmpty({ message: '验证码不能为空' })
  @Matches(/^\d{6}$/, { message: '验证码格式错误' })
  smsCode: string;
}

export class SubmitIdVerificationDto {
  @ApiProperty({
    example: '张三',
    description: '真实姓名',
  })
  @IsString()
  @IsNotEmpty({ message: '姓名不能为空' })
  @Length(2, 50, { message: '姓名长度应为2-50个字符' })
  realName: string;

  @ApiProperty({
    example: '110101199001011234',
    description: '18位身份证号码',
  })
  @IsString()
  @IsNotEmpty({ message: '身份证号不能为空' })
  @Matches(/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/, {
    message: '身份证号格式错误',
  })
  idCardNumber: string;
}

// ============ Response DTOs ============

export class KycStatusResponseDto {
  @ApiProperty({ description: '手机号是否已验证' })
  phoneVerified: boolean;

  @ApiProperty({
    description: 'KYC 状态: NOT_STARTED, PHONE_VERIFIED, ID_PENDING, ID_VERIFIED, COMPLETED, REJECTED',
  })
  kycStatus: string;

  @ApiPropertyOptional({ description: '脱敏后的真实姓名 (如: 张*)' })
  realName?: string;

  @ApiPropertyOptional({ description: '脱敏后的身份证号 (如: 1101***********234)' })
  idCardNumber?: string;

  @ApiPropertyOptional({ description: 'KYC 完成时间' })
  kycVerifiedAt?: Date;

  @ApiPropertyOptional({ description: '拒绝原因 (状态为 REJECTED 时返回)' })
  rejectedReason?: string;

  @ApiPropertyOptional({ description: '脱敏后的手机号' })
  phoneNumber?: string;
}

export class IdVerificationResponseDto {
  @ApiProperty({ description: '验证请求 ID' })
  requestId: string;

  @ApiProperty({
    description: '验证状态: SUCCESS, FAILED, PENDING',
  })
  status: string;

  @ApiPropertyOptional({ description: '失败原因' })
  failureReason?: string;

  @ApiPropertyOptional({ description: '更新后的 KYC 状态' })
  kycStatus?: string;
}
