import { Transform } from 'class-transformer';
import {
  IsEmail,
  IsNumber,
  IsNotEmpty,
  IsStrongPassword,
} from 'class-validator';
import { IsAlphaWithMessage } from 'src/common/errors/custom-validation-message';

export class CreateUserDto {
  @IsNotEmpty({ message: 'First name should not be empty.' })
  @IsAlphaWithMessage({ message: 'First Name should be only alphabetic.' })
  @Transform(({ value }) => value.trim().replace(/\s+/g, ' '))
  first_name: string;

  @Transform(({ value }) => value.trim().replace(/\s+/g, ' '))
  middle_name: string;

  @Transform(({ value }) => value.trim().replace(/\s+/g, ' '))
  last_name: string;

  @IsNotEmpty({ message: 'Password cannot be empty.' })
  @IsStrongPassword(
    {
      minLength: 8,
      minLowercase: 1,
      minNumbers: 1,
      minSymbols: 1,
      minUppercase: 1,
    },
    { message: `Password is not strong enough.` },
  )
  password: string;

  @IsEmail({}, { message: 'Invalid email address.' })
  @IsNotEmpty({ message: 'Email should not be empty.' })
  @Transform(({ value }) => value.trim().replace(/\s+/g, ' '))
  email: string;

  @IsNumber({}, { message: 'Contact number must be a number.' })
  @IsNotEmpty({ message: 'Contact number should not be empty.' })
  @Transform(({ value }) =>
    typeof value === 'string' ? parseFloat(value.replace(/\s+/g, '')) : value,
  )
  contact_no: number;

  //   @IsNumber({}, { message: 'Each batch year must be a number.' })
  batch: number;

  profile_picture: string;

  home_town: string;

  city_id: string;

  course: string[];

  job_id: string;

  date_of_birth: any;

  designation: string;

  company_name: string;

  company_address: string;
}
