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

export class EnviarCodigoDto {
  @ApiProperty({ example: 'email@example.com' })
  @ValidateIf((o: EnviarCodigoDto) => o.tipo === 'email')
  @IsEmail({}, { message: 'Email debe tener un formato válido' })
  @IsNotEmpty({ message: 'Email debe tener un formato válido' })
  @Length(3, 80, { message: 'Email debe tener entre 3 y 80 caracteres' })
  @IsOptional()
  email?: string;

  @ApiProperty({ example: '595981743120' })
  @ValidateIf((o: EnviarCodigoDto) => o.tipo === 'celular')
  @IsNotEmpty({ message: 'Celular debe tener entre 10 y 20 caracteres' })
  @Length(10, 20, { message: 'Celular debe tener entre 10 y 20 caracteres' })
  @IsString()
  @IsOptional()
  celular?: string;

  @ApiProperty({ example: 'email', description: 'Tipo de verificación' })
  @IsNotEmpty({ message: 'Tipo es obligatorio' })
  @IsString()
  @IsIn(['celular', 'email'], { message: 'Tipo debe ser "celular" o "email"' })
  tipo: 'celular' | 'email';
}
