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

export class LoginDto {
  @IsString()
  @IsIn(['phone_number', 'username'])
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Login Type',
    enum: ['phone_number', 'username'],
  })
  type: string;

  @ValidateIf((o) => o.type === 'phone_number')
  @IsNotEmpty()
  @IsString({ message: `Mobile number can't be empty` })
  @ApiProperty({
    required: true,
    type: String,
    description: 'Phone number',
  })
  phone_number: string;

  @ValidateIf((o) => o.type === 'phone_number')
  @IsNotEmpty()
  @IsString()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Country Code',
  })
  country_phone_code: string;

  @ValidateIf((o) => o.type === 'username')
  @IsNotEmpty()
  @IsString()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Username',
  })
  username: string;

  @ValidateIf((o) => o.type === 'username')
  @IsNotEmpty({ message: `Password can't be empty.` })
  @IsString()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Password',
  })
  password: string;

  @IsString()
  @IsIn(['ios', 'android'])
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Device Type',
  })
  device_type: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Device Type',
  })
  device_id: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Device Token',
  })
  device_token: string;
}
