// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.cloud.pubsublite;

import com.google.auth.oauth2.GoogleCredentials;
import io.grpc.Channel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.auth.MoreCallCredentials;
import io.grpc.stub.AbstractStub;
import java.io.IOException;
import java.util.function.Function;

public class Stubs {
  public static <StubT extends AbstractStub<StubT>> StubT defaultStub(
      String target, Function<Channel, StubT> stubFactory) throws IOException {
    return stubFactory
        .apply(ManagedChannelBuilder.forTarget(target).build())
        .withCallCredentials(MoreCallCredentials.from(GoogleCredentials.getApplicationDefault()));
  }

  private Stubs() {}
}

@@ -661,32 +661,80 @@
 gleCredentials;%0A
+import com.google.common.collect.ImmutableList;%0A
 import io.grpc.C
@@ -741,16 +741,16 @@
 hannel;%0A
-
 import i
@@ -940,16 +940,159 @@
 Stubs %7B%0A
+  private static final ImmutableList%3CString%3E DEFAULT_SERVICE_SCOPES =%0A    ImmutableList.of(%22https://www.googleapis.com/auth/cloud-platform%22);%0A%0A
   public
@@ -1375,16 +1375,27 @@
 ls.from(
+%0A          
 GoogleCr
@@ -1403,16 +1403,29 @@
 dentials
+%0A            
 .getAppl
@@ -1440,16 +1440,66 @@
 efault()
+%0A            .createScoped(DEFAULT_SERVICE_SCORES)
 ));%0A  %7D%0A

add scope codes to the stub provider