import { IsEmail, IsString, MinLength, IsEnum, Matches } from 'class-validator';
import { isValidIranMobile } from '../../../common/utils/mobile.util';
import { ErrorCode } from '../../../common/errors';

export class RegisterDto {
  @IsEmail({}, { message: ErrorCode.VALIDATION_EMAIL_INVALID })
  email: string;

  @IsString()
  @Matches(/^[\d+\s()-]+$/, { message: ErrorCode.VALIDATION_MOBILE_INVALID })
  mobile: string;

  @IsString()
  @MinLength(8, { message: ErrorCode.VALIDATION_PASSWORD_TOO_SHORT })
  password: string;

  @IsString()
  @MinLength(2, { message: ErrorCode.VALIDATION_NAME_TOO_SHORT })
  name: string;

  @IsString()
  @MinLength(2, { message: ErrorCode.VALIDATION_ORGANIZATION_NAME_REQUIRED })
  organizationName: string;

  @IsEmail({}, { message: ErrorCode.VALIDATION_EMAIL_INVALID })
  organizationEmail: string;

  @IsEnum(['CLINIC', 'LAB'], { message: ErrorCode.VALIDATION_ORGANIZATION_TYPE_INVALID })
  organizationType: 'CLINIC' | 'LAB';

  static isValidMobile(mobile: string): boolean {
    return isValidIranMobile(mobile);
  }
}
