import { IsString, IsNotEmpty, IsEmail, ValidateIf } from 'class-validator';
import { Transform } from 'class-transformer';

export class LoginDto {
  @ValidateIf(o => !o.email)
  @IsString()
  @IsNotEmpty()
  username?: string;

  @ValidateIf(o => !o.username)
  @IsString()
  @IsNotEmpty()
  @IsEmail()
  email?: string;

  @Transform(({ value }) => value?.trim())
  @IsString()
  @IsNotEmpty()
  password: string;

  // Helper method to get the email (either from email or username field)
  getEmail(): string {
    return this.email || this.username;
  }
}
