class UserService {

  public void checkKeyUniqueness(String key, String value, boolean isEncrypted) {
    if (StringUtils.isBlank(key) || StringUtils.isBlank(value)) {
      ProjectLogger.log(
          "UserService:checkKeyUniqueness: Key or value is null. key = "
              + key
              + " value= "
              + value,
          LoggerEnum.ERROR.name());
      return;
    }
    String val = value;
    if (isEncrypted) {
      try {
        val = getEncryptionService().encryptData(val);
      } catch (Exception e) {
        ProjectLogger.log(
            "UserService:checkKeyUniqueness: Exception occurred with error message = "
                + e.getMessage(),
            e);
      }
    }

    Response result = getCassandraOperation().getRecordsByIndexedProperty(userDb.getKeySpace(), userDb.getTableName(), key, val);

    List<Map<String, Object>> userMapList =
        (List<Map<String, Object>>) result.get(JsonKey.RESPONSE);

    if (!userMapList.isEmpty()) {
      ResponseCode responseCode = null;
      if (JsonKey.EMAIL.equals(key)) {
        responseCode = ResponseCode.emailInUse;
      } else if (JsonKey.PHONE.equals(key)) {
        responseCode = ResponseCode.PhoneNumberInUse;
      }
      ProjectCommonException.throwClientErrorException(responseCode, null);
    }
  }

}