/*
 * Copyright 2026 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
 *
 *      https://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.logging.v2;

import com.google.api.core.BetaApi;
import com.google.logging.v2.CmekSettings;
import com.google.logging.v2.ConfigServiceV2Grpc.ConfigServiceV2ImplBase;
import com.google.logging.v2.CopyLogEntriesRequest;
import com.google.logging.v2.CreateBucketRequest;
import com.google.logging.v2.CreateExclusionRequest;
import com.google.logging.v2.CreateSinkRequest;
import com.google.logging.v2.CreateViewRequest;
import com.google.logging.v2.DeleteBucketRequest;
import com.google.logging.v2.DeleteExclusionRequest;
import com.google.logging.v2.DeleteSinkRequest;
import com.google.logging.v2.DeleteViewRequest;
import com.google.logging.v2.GetBucketRequest;
import com.google.logging.v2.GetCmekSettingsRequest;
import com.google.logging.v2.GetExclusionRequest;
import com.google.logging.v2.GetSettingsRequest;
import com.google.logging.v2.GetSinkRequest;
import com.google.logging.v2.GetViewRequest;
import com.google.logging.v2.ListBucketsRequest;
import com.google.logging.v2.ListBucketsResponse;
import com.google.logging.v2.ListExclusionsRequest;
import com.google.logging.v2.ListExclusionsResponse;
import com.google.logging.v2.ListSinksRequest;
import com.google.logging.v2.ListSinksResponse;
import com.google.logging.v2.ListViewsRequest;
import com.google.logging.v2.ListViewsResponse;
import com.google.logging.v2.LogBucket;
import com.google.logging.v2.LogExclusion;
import com.google.logging.v2.LogSink;
import com.google.logging.v2.LogView;
import com.google.logging.v2.Settings;
import com.google.logging.v2.UndeleteBucketRequest;
import com.google.logging.v2.UpdateBucketRequest;
import com.google.logging.v2.UpdateCmekSettingsRequest;
import com.google.logging.v2.UpdateExclusionRequest;
import com.google.logging.v2.UpdateSettingsRequest;
import com.google.logging.v2.UpdateSinkRequest;
import com.google.logging.v2.UpdateViewRequest;
import com.google.longrunning.Operation;
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.Empty;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import javax.annotation.Generated;

@BetaApi
@Generated("by gapic-generator-java")
public class MockConfigServiceV2Impl extends ConfigServiceV2ImplBase {
  private List<AbstractMessage> requests;
  private Queue<Object> responses;

  public MockConfigServiceV2Impl() {
    requests = new ArrayList<>();
    responses = new LinkedList<>();
  }

  public List<AbstractMessage> getRequests() {
    return requests;
  }

  public void addResponse(AbstractMessage response) {
    responses.add(response);
  }

  public void setResponses(List<AbstractMessage> responses) {
    this.responses = new LinkedList<Object>(responses);
  }

  public void addException(Exception exception) {
    responses.add(exception);
  }

  public void reset() {
    requests = new ArrayList<>();
    responses = new LinkedList<>();
  }

  @Override
  public void listBuckets(
      ListBucketsRequest request, StreamObserver<ListBucketsResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListBucketsResponse) {
      requests.add(request);
      responseObserver.onNext(((ListBucketsResponse) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method ListBuckets, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListBucketsResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getBucket(GetBucketRequest request, StreamObserver<LogBucket> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogBucket) {
      requests.add(request);
      responseObserver.onNext(((LogBucket) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetBucket, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogBucket.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createBucket(
      CreateBucketRequest request, StreamObserver<LogBucket> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogBucket) {
      requests.add(request);
      responseObserver.onNext(((LogBucket) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method CreateBucket, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogBucket.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateBucket(
      UpdateBucketRequest request, StreamObserver<LogBucket> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogBucket) {
      requests.add(request);
      responseObserver.onNext(((LogBucket) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateBucket, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogBucket.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteBucket(DeleteBucketRequest request, StreamObserver<Empty> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Empty) {
      requests.add(request);
      responseObserver.onNext(((Empty) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method DeleteBucket, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Empty.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void undeleteBucket(
      UndeleteBucketRequest request, StreamObserver<Empty> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Empty) {
      requests.add(request);
      responseObserver.onNext(((Empty) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UndeleteBucket, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Empty.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listViews(
      ListViewsRequest request, StreamObserver<ListViewsResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListViewsResponse) {
      requests.add(request);
      responseObserver.onNext(((ListViewsResponse) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method ListViews, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListViewsResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getView(GetViewRequest request, StreamObserver<LogView> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogView) {
      requests.add(request);
      responseObserver.onNext(((LogView) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetView, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogView.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createView(CreateViewRequest request, StreamObserver<LogView> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogView) {
      requests.add(request);
      responseObserver.onNext(((LogView) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method CreateView, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogView.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateView(UpdateViewRequest request, StreamObserver<LogView> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogView) {
      requests.add(request);
      responseObserver.onNext(((LogView) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateView, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogView.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteView(DeleteViewRequest request, StreamObserver<Empty> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Empty) {
      requests.add(request);
      responseObserver.onNext(((Empty) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method DeleteView, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Empty.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listSinks(
      ListSinksRequest request, StreamObserver<ListSinksResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListSinksResponse) {
      requests.add(request);
      responseObserver.onNext(((ListSinksResponse) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method ListSinks, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListSinksResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getSink(GetSinkRequest request, StreamObserver<LogSink> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogSink) {
      requests.add(request);
      responseObserver.onNext(((LogSink) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetSink, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogSink.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createSink(CreateSinkRequest request, StreamObserver<LogSink> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogSink) {
      requests.add(request);
      responseObserver.onNext(((LogSink) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method CreateSink, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogSink.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateSink(UpdateSinkRequest request, StreamObserver<LogSink> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogSink) {
      requests.add(request);
      responseObserver.onNext(((LogSink) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateSink, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogSink.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteSink(DeleteSinkRequest request, StreamObserver<Empty> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Empty) {
      requests.add(request);
      responseObserver.onNext(((Empty) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method DeleteSink, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Empty.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listExclusions(
      ListExclusionsRequest request, StreamObserver<ListExclusionsResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListExclusionsResponse) {
      requests.add(request);
      responseObserver.onNext(((ListExclusionsResponse) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method ListExclusions, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListExclusionsResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getExclusion(
      GetExclusionRequest request, StreamObserver<LogExclusion> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogExclusion) {
      requests.add(request);
      responseObserver.onNext(((LogExclusion) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetExclusion, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogExclusion.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createExclusion(
      CreateExclusionRequest request, StreamObserver<LogExclusion> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogExclusion) {
      requests.add(request);
      responseObserver.onNext(((LogExclusion) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method CreateExclusion, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogExclusion.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateExclusion(
      UpdateExclusionRequest request, StreamObserver<LogExclusion> responseObserver) {
    Object response = responses.poll();
    if (response instanceof LogExclusion) {
      requests.add(request);
      responseObserver.onNext(((LogExclusion) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateExclusion, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  LogExclusion.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteExclusion(
      DeleteExclusionRequest request, StreamObserver<Empty> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Empty) {
      requests.add(request);
      responseObserver.onNext(((Empty) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method DeleteExclusion, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Empty.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getCmekSettings(
      GetCmekSettingsRequest request, StreamObserver<CmekSettings> responseObserver) {
    Object response = responses.poll();
    if (response instanceof CmekSettings) {
      requests.add(request);
      responseObserver.onNext(((CmekSettings) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetCmekSettings, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  CmekSettings.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateCmekSettings(
      UpdateCmekSettingsRequest request, StreamObserver<CmekSettings> responseObserver) {
    Object response = responses.poll();
    if (response instanceof CmekSettings) {
      requests.add(request);
      responseObserver.onNext(((CmekSettings) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateCmekSettings, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  CmekSettings.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getSettings(GetSettingsRequest request, StreamObserver<Settings> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Settings) {
      requests.add(request);
      responseObserver.onNext(((Settings) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method GetSettings, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Settings.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateSettings(
      UpdateSettingsRequest request, StreamObserver<Settings> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Settings) {
      requests.add(request);
      responseObserver.onNext(((Settings) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method UpdateSettings, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Settings.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void copyLogEntries(
      CopyLogEntriesRequest request, StreamObserver<Operation> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Operation) {
      requests.add(request);
      responseObserver.onNext(((Operation) response));
      responseObserver.onCompleted();
    } else if (response instanceof Exception) {
      responseObserver.onError(((Exception) response));
    } else {
      responseObserver.onError(
          new IllegalArgumentException(
              String.format(
                  "Unrecognized response type %s for method CopyLogEntries, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }
}
