class PermAddNodesToAllowlist implements JsonRpcMethod {

  @Override
  public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final StringListParameter enodeListParam =
        requestContext.getRequiredParameter(0, StringListParameter.class);

    try {
      if (nodeWhitelistPermissioningController.isPresent()) {
        try {
          final List<String> enodeURLs = enodeListParam.getStringList();
          final NodesAllowlistResult nodesAllowlistResult =
              nodeWhitelistPermissioningController.get().addNodes(enodeURLs);

          switch (nodesAllowlistResult.result()) {
            case SUCCESS:
              return new JsonRpcSuccessResponse(requestContext.getRequest().getId());
            case ERROR_EMPTY_ENTRY:
              return new JsonRpcErrorResponse(
                  requestContext.getRequest().getId(), JsonRpcError.NODE_ALLOWLIST_EMPTY_ENTRY);
            case ERROR_EXISTING_ENTRY:
              return new JsonRpcErrorResponse(
                  requestContext.getRequest().getId(), JsonRpcError.NODE_ALLOWLIST_EXISTING_ENTRY);
            case ERROR_DUPLICATED_ENTRY:
              return new JsonRpcErrorResponse(
                  requestContext.getRequest().getId(),
                  JsonRpcError.NODE_ALLOWLIST_DUPLICATED_ENTRY);
            case ERROR_ALLOWLIST_PERSIST_FAIL:
              return new JsonRpcErrorResponse(
                  requestContext.getRequest().getId(), JsonRpcError.ALLOWLIST_PERSIST_FAILURE);
            case ERROR_ALLOWLIST_FILE_SYNC:
              return new JsonRpcErrorResponse(
                  requestContext.getRequest().getId(), JsonRpcError.ALLOWLIST_FILE_SYNC);
            default:
              throw new Exception();
          }
        } catch (IllegalArgumentException e) {
          return new JsonRpcErrorResponse(
              requestContext.getRequest().getId(), JsonRpcError.NODE_ALLOWLIST_INVALID_ENTRY);
        } catch (Exception e) {
          return new JsonRpcErrorResponse(
              requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR);
        }
      } else {
        return new JsonRpcErrorResponse(
            requestContext.getRequest().getId(), JsonRpcError.NODE_ALLOWLIST_NOT_ENABLED);
      }
    } catch (P2PDisabledException e) {
      return new JsonRpcErrorResponse(
          requestContext.getRequest().getId(), JsonRpcError.P2P_DISABLED);
    }
  }

  public  PermAddNodesToAllowlist(
      final Optional<NodeLocalConfigPermissioningController> nodeWhitelistPermissioningController);

}