import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { 
  IsEmail, IsEnum, IsString, Matches, MaxLength, MinLength, IsOptional, IsBoolean 
} from 'class-validator';
import { UserRole } from 'common/enum/UserRole.enum';

export class CreateAdminDto {
  @ApiProperty({
    example: 'admin@example.com',
    description: 'admin email address',
  })
  @IsEmail({}, { message: 'Invalid email format' })
  email: string;

  @ApiProperty({
    example: 'Password123!',
    description:
      'Password must be 6-32 characters long, include at least one uppercase letter, one lowercase letter, one number, and one special character',
  })
  @IsString({ message: 'Password must be a string' })
  @MinLength(6, { message: 'Password must be at least 6 characters long' })
  @MaxLength(32, { message: 'Password cannot be longer than 32 characters' })
  @Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/, {
    message: 'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character (@$!%*?&)',
  })
  password: string;

  @ApiProperty({
    enum: UserRole,
    example: UserRole.SUPER_ADMIN,
    description: `User role (default: ${UserRole.SUPER_ADMIN})`,
    default: UserRole.USER,
  })
  @IsEnum(UserRole, { message: 'Invalid role' })
  role: UserRole = UserRole.ADMIN;

  // @ValidateIf(dto => dto.role === UserRole.ADMIN || dto.role === UserRole.SUPER_ADMIN)
  // @ApiPropertyOptional({
  //   example: 'referral@example.com',
  //   description: 'Referral email (required if role is ADMIN or SUPERADMIN)',
  // })
  // @IsEmail({}, { message: 'Invalid referral email format' })
  // referralMail?: string;

  @ApiProperty({
    example: 'John',
    description: 'User first name',
  })
  @IsString({ message: 'First name must be a string' })
  firstName: string;

  @ApiProperty({
    example: 'Doe',
    description: 'User last name',
  })
  @IsString({ message: 'Last name must be a string' })
  lastName: string;

  @ApiPropertyOptional({
    example: 'https://example.com/picture.jpg',
    description: 'User profile picture',
  })
  @IsOptional()
  @IsString({ message: 'Picture must be a string' })
  picture?: string;

  @ApiPropertyOptional({
    example: 'googleId123',
    description: 'Google ID',
  })
  @IsOptional()
  @IsString({ message: 'Google ID must be a string' })
  googleId?: string;

  @ApiPropertyOptional({
    example: false,
    description: 'Is Google user',
  })
  @IsOptional()
  @IsBoolean({ message: 'Is Google user must be a boolean' })
  isGoogleUser?: boolean;
}
