class AlterQueryServiceFunction extends CliFunction<Object[]> {

  @Override
  @SuppressWarnings({"unchecked", "deprecation"})
  public CliFunctionResult executeFunction(FunctionContext<Object[]> context) {
    Set<String> parameterSet;
    boolean forceUpdate = (boolean) context.getArguments()[0];
    String authorizerName = (String) context.getArguments()[1];

    if (context.getArguments()[2] != null) {
      parameterSet = (Set<String>) context.getArguments()[2];
    } else {
      parameterSet = Collections.emptySet();
    }

    if (StringUtils.isEmpty(authorizerName)) {
      return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR,
          EMPTY_AUTHORIZER_ERROR);
    }

    if (!isSecurityEnabled()) {
      return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR,
          SECURITY_NOT_ENABLED_MESSAGE);
    }

    if (Boolean
        .parseBoolean(System.getProperty(ALLOW_UNTRUSTED_METHOD_INVOCATION_SYSTEM_PROPERTY))) {
      return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR,
          DEPRECATED_PROPERTY_ERROR);
    }

    try {
      Cache cache = context.getCache();
      ((InternalCache) cache).getService(QueryConfigurationService.class)
          .updateMethodAuthorizer(cache, forceUpdate, authorizerName, parameterSet);
    } catch (Exception ex) {
      return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.ERROR,
          ex.getMessage());
    }

    String message = AUTHORIZER_UPDATED_MESSAGE + authorizerName + (parameterSet.size() > 0
        ? AUTHORIZER_PARAMETERS_MESSAGE + String.join(", ", parameterSet) : "");
    return new CliFunctionResult(context.getMemberName(), CliFunctionResult.StatusState.OK,
        message);
  }

}