import { ApiProperty } from '@nestjs/swagger';
import {
  IsIn,
  IsNotEmpty,
  IsString,
  IsStrongPassword,
  ValidateIf,
} from 'class-validator';

export class ChangePasswordDto {
  @IsString()
  @IsIn(['change_password', 'forgot_password'])
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    enum: ['change_password', 'forgot_password'],
    description: 'Change Password Type',
  })
  type: string;

  @ValidateIf((o) => o.type === 'change_password')
  @IsString()
  @IsNotEmpty({ message: 'Old password is required.' })
  @ApiProperty({
    required: true,
    type: String,
    description: 'Old Password',
  })
  old_password: string;

  @IsString()
  @IsStrongPassword(undefined, {
    message: 'New Password must be strong.',
  })
  @IsNotEmpty({ message: 'New password is required.' })
  @ApiProperty({
    required: true,
    type: String,
    description: 'New Password',
  })
  new_password: string;

  @IsString()
  @IsStrongPassword(undefined, {
    message: 'New Password must be strong.',
  })
  @IsNotEmpty({ message: 'Please re-enter new password.' })
  @ApiProperty({
    required: true,
    type: String,
    description: 'Confirm Password',
  })
  confirm_password: string;
}
