import { IsNumber, IsString, IsOptional, IsEnum, Min, IsInt } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

// 用户提现
export class CreateUserWithdrawalDto {
  @ApiProperty({ description: '提现金额', example: 50 })
  @IsNumber()
  @Min(10, { message: '最低提现金额为10元' })
  amount: number;

  @ApiProperty({ description: '支付渠道', enum: ['wechat', 'alipay'] })
  @IsEnum(['wechat', 'alipay'])
  paymentChannel: 'wechat' | 'alipay';
}

export class QueryUserWithdrawalDto {
  @ApiPropertyOptional({ description: '状态', enum: ['pending', 'approved', 'rejected', 'paid'] })
  @IsOptional()
  @IsEnum(['pending', 'approved', 'rejected', 'paid'])
  status?: string;

  @ApiPropertyOptional({ description: '页码', example: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number = 1;

  @ApiPropertyOptional({ description: '每页数量', example: 20 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  pageSize?: number = 20;
}

// 商家提现
export class CreateMerchantWithdrawalDto {
  @ApiProperty({ description: '提现金额', example: 500 })
  @IsNumber()
  @Min(100, { message: '最低提现金额为100元' })
  amount: number;

  @ApiProperty({ description: '银行名称', example: '中国工商银行' })
  @IsString()
  bankName: string;

  @ApiProperty({ description: '银行账号', example: '6222021234567890123' })
  @IsString()
  bankAccount: string;

  @ApiProperty({ description: '账户名', example: '张三' })
  @IsString()
  accountName: string;
}

export class QueryMerchantWithdrawalDto {
  @ApiPropertyOptional({ description: '状态', enum: ['pending', 'approved', 'rejected', 'paid'] })
  @IsOptional()
  @IsEnum(['pending', 'approved', 'rejected', 'paid'])
  status?: string;

  @ApiPropertyOptional({ description: '页码', example: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number = 1;

  @ApiPropertyOptional({ description: '每页数量', example: 20 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  pageSize?: number = 20;
}

// 平台提现
export class CreatePlatformWithdrawalDto {
  @ApiProperty({ description: '提现金额', example: 10000 })
  @IsNumber()
  @Min(10, { message: '最低提现金额为10元' })
  amount: number;

  @ApiProperty({ description: '银行名称', example: '中国工商银行' })
  @IsString()
  bankName: string;

  @ApiProperty({ description: '银行账号', example: '6222021234567890123' })
  @IsString()
  bankAccount: string;

  @ApiProperty({ description: '账户名', example: '某某公司' })
  @IsString()
  accountName: string;
}

export class QueryPlatformWithdrawalDto {
  @ApiPropertyOptional({ description: '状态', enum: ['pending', 'approved', 'rejected', 'paid'] })
  @IsOptional()
  @IsEnum(['pending', 'approved', 'rejected', 'paid'])
  status?: string;

  @ApiPropertyOptional({ description: '页码', example: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number = 1;

  @ApiPropertyOptional({ description: '每页数量', example: 20 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  pageSize?: number = 20;
}

// 审核
export class RejectWithdrawalDto {
  @ApiProperty({ description: '拒绝原因' })
  @IsString()
  rejectReason: string;
}

export class ConfirmPaymentDto {
  @ApiPropertyOptional({ description: '第三方支付单号' })
  @IsOptional()
  @IsString()
  paymentNo?: string;
}
