import { IsString, MinLength, IsOptional, IsNumber } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class LoginDto {
  @ApiProperty()
  @IsString()
  username!: string;

  @ApiProperty()
  @IsString()
  @MinLength(1)
  password!: string;

  @ApiProperty({ required: false, description: '国家区号，不含 +，如 86' })
  @IsOptional()
  @IsString()
  countryCode?: string;
}

export class RegisterDto {
  @ApiProperty({ description: '登录账号，7-32 位字母数字' })
  @IsString()
  @MinLength(7)
  username!: string;

  @ApiProperty({ description: '本地手机号，不含国家区号' })
  @IsString()
  phone!: string;

  @ApiProperty({ description: '国家区号，不含 +，如 86' })
  @IsString()
  countryCode!: string;

  @ApiProperty()
  @IsString()
  @MinLength(8)
  password!: string;

  @ApiProperty({ description: '短信验证码' })
  @IsString()
  smsCode!: string;

  @ApiProperty({ description: '发送验证码返回的 sessionId' })
  @IsString()
  sessionId!: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  inviteCode?: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  locale?: string;
}

export class ChangePasswordDto {
  @ApiProperty()
  @IsString()
  oldPassword!: string;

  @ApiProperty()
  @IsString()
  @MinLength(8)
  newPassword!: string;
}

export class ForgotPasswordDto {
  @ApiProperty({ description: '本地手机号，不含国家区号' })
  @IsString()
  phone!: string;

  @ApiProperty({ description: '国家区号，不含 +，如 86' })
  @IsString()
  countryCode!: string;

  @ApiProperty({ description: '短信验证码' })
  @IsString()
  smsCode!: string;

  @ApiProperty({ description: '发送验证码返回的 sessionId' })
  @IsString()
  sessionId!: string;

  @ApiProperty()
  @IsString()
  @MinLength(8)
  newPassword!: string;
}

export class GenerateInviteDto {
  @ApiProperty({ required: false, description: 'Decimal cashback rate, e.g. 0.01 = 1%. Admin only.' })
  @IsOptional()
  @IsNumber()
  cashbackRate?: number;
}
