import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsString, IsOptional, IsEnum, Min, ValidateIf } from 'class-validator';
import { PaymentMethod } from '@/domain/value-objects/fiat-withdrawal-status.enum';

/**
 * 法币提现请求 DTO
 */
export class RequestFiatWithdrawalDTO {
  @ApiProperty({ description: '提现金额 (绿积分)', example: 100 })
  @IsNumber()
  @Min(100, { message: '最小提现金额为 100 绿积分' })
  amount: number;

  @ApiProperty({ description: '收款方式', enum: PaymentMethod, example: 'BANK_CARD' })
  @IsEnum(PaymentMethod)
  paymentMethod: PaymentMethod;

  // 银行卡信息
  @ApiPropertyOptional({ description: '银行名称', example: '中国工商银行' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.BANK_CARD)
  @IsString()
  bankName?: string;

  @ApiPropertyOptional({ description: '银行卡号', example: '6222021234567890123' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.BANK_CARD)
  @IsString()
  bankCardNo?: string;

  @ApiPropertyOptional({ description: '持卡人姓名', example: '张三' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.BANK_CARD)
  @IsString()
  cardHolderName?: string;

  // 支付宝信息
  @ApiPropertyOptional({ description: '支付宝账号', example: '13800138000' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.ALIPAY)
  @IsString()
  alipayAccount?: string;

  @ApiPropertyOptional({ description: '支付宝实名', example: '张三' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.ALIPAY)
  @IsString()
  alipayRealName?: string;

  // 微信信息
  @ApiPropertyOptional({ description: '微信账号', example: 'wxid_abc123' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.WECHAT)
  @IsString()
  wechatAccount?: string;

  @ApiPropertyOptional({ description: '微信实名', example: '张三' })
  @ValidateIf(o => o.paymentMethod === PaymentMethod.WECHAT)
  @IsString()
  wechatRealName?: string;

  // 验证
  @ApiProperty({ description: '短信验证码', example: '123456' })
  @IsString()
  smsCode: string;

  @ApiProperty({ description: '登录密码', example: 'password123' })
  @IsString()
  password: string;
}

/**
 * 审核法币提现 DTO
 */
export class ReviewFiatWithdrawalDTO {
  @ApiProperty({ description: '是否通过', example: true })
  approved: boolean;

  @ApiPropertyOptional({ description: '审核备注', example: '信息核实无误' })
  @IsOptional()
  @IsString()
  remark?: string;
}

/**
 * 开始打款 DTO
 */
export class StartPaymentDTO {
  // 无需额外参数，操作人从 JWT 中获取
}

/**
 * 完成打款 DTO
 */
export class CompletePaymentDTO {
  @ApiPropertyOptional({ description: '打款凭证', example: 'https://example.com/proof.jpg' })
  @IsOptional()
  @IsString()
  paymentProof?: string;

  @ApiPropertyOptional({ description: '打款备注', example: '已打款至工商银行' })
  @IsOptional()
  @IsString()
  remark?: string;
}

/**
 * 取消法币提现 DTO
 */
export class CancelFiatWithdrawalDTO {
  @ApiPropertyOptional({ description: '取消原因', example: '用户主动取消' })
  @IsOptional()
  @IsString()
  reason?: string;
}
