/*
 * Copyright 2022 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.gkebackup.v1;

import com.google.api.core.BetaApi;
import com.google.cloud.gkebackup.v1.BackupForGKEGrpc.BackupForGKEImplBase;
import com.google.longrunning.Operation;
import com.google.protobuf.AbstractMessage;
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 MockBackupForGKEImpl extends BackupForGKEImplBase {
  private List<AbstractMessage> requests;
  private Queue<Object> responses;

  public MockBackupForGKEImpl() {
    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 createBackupPlan(
      CreateBackupPlanRequest 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 CreateBackupPlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listBackupPlans(
      ListBackupPlansRequest request, StreamObserver<ListBackupPlansResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListBackupPlansResponse) {
      requests.add(request);
      responseObserver.onNext(((ListBackupPlansResponse) 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 ListBackupPlans, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListBackupPlansResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getBackupPlan(
      GetBackupPlanRequest request, StreamObserver<BackupPlan> responseObserver) {
    Object response = responses.poll();
    if (response instanceof BackupPlan) {
      requests.add(request);
      responseObserver.onNext(((BackupPlan) 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 GetBackupPlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  BackupPlan.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateBackupPlan(
      UpdateBackupPlanRequest 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 UpdateBackupPlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteBackupPlan(
      DeleteBackupPlanRequest 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 DeleteBackupPlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createBackup(
      CreateBackupRequest 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 CreateBackup, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listBackups(
      ListBackupsRequest request, StreamObserver<ListBackupsResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListBackupsResponse) {
      requests.add(request);
      responseObserver.onNext(((ListBackupsResponse) 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 ListBackups, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListBackupsResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getBackup(GetBackupRequest request, StreamObserver<Backup> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Backup) {
      requests.add(request);
      responseObserver.onNext(((Backup) 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 GetBackup, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Backup.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateBackup(
      UpdateBackupRequest 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 UpdateBackup, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteBackup(
      DeleteBackupRequest 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 DeleteBackup, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listVolumeBackups(
      ListVolumeBackupsRequest request,
      StreamObserver<ListVolumeBackupsResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListVolumeBackupsResponse) {
      requests.add(request);
      responseObserver.onNext(((ListVolumeBackupsResponse) 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 ListVolumeBackups, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListVolumeBackupsResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getVolumeBackup(
      GetVolumeBackupRequest request, StreamObserver<VolumeBackup> responseObserver) {
    Object response = responses.poll();
    if (response instanceof VolumeBackup) {
      requests.add(request);
      responseObserver.onNext(((VolumeBackup) 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 GetVolumeBackup, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  VolumeBackup.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createRestorePlan(
      CreateRestorePlanRequest 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 CreateRestorePlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listRestorePlans(
      ListRestorePlansRequest request, StreamObserver<ListRestorePlansResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListRestorePlansResponse) {
      requests.add(request);
      responseObserver.onNext(((ListRestorePlansResponse) 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 ListRestorePlans, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListRestorePlansResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getRestorePlan(
      GetRestorePlanRequest request, StreamObserver<RestorePlan> responseObserver) {
    Object response = responses.poll();
    if (response instanceof RestorePlan) {
      requests.add(request);
      responseObserver.onNext(((RestorePlan) 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 GetRestorePlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  RestorePlan.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateRestorePlan(
      UpdateRestorePlanRequest 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 UpdateRestorePlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteRestorePlan(
      DeleteRestorePlanRequest 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 DeleteRestorePlan, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void createRestore(
      CreateRestoreRequest 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 CreateRestore, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listRestores(
      ListRestoresRequest request, StreamObserver<ListRestoresResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListRestoresResponse) {
      requests.add(request);
      responseObserver.onNext(((ListRestoresResponse) 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 ListRestores, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListRestoresResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getRestore(GetRestoreRequest request, StreamObserver<Restore> responseObserver) {
    Object response = responses.poll();
    if (response instanceof Restore) {
      requests.add(request);
      responseObserver.onNext(((Restore) 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 GetRestore, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Restore.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void updateRestore(
      UpdateRestoreRequest 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 UpdateRestore, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void deleteRestore(
      DeleteRestoreRequest 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 DeleteRestore, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  Operation.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void listVolumeRestores(
      ListVolumeRestoresRequest request,
      StreamObserver<ListVolumeRestoresResponse> responseObserver) {
    Object response = responses.poll();
    if (response instanceof ListVolumeRestoresResponse) {
      requests.add(request);
      responseObserver.onNext(((ListVolumeRestoresResponse) 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 ListVolumeRestores, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  ListVolumeRestoresResponse.class.getName(),
                  Exception.class.getName())));
    }
  }

  @Override
  public void getVolumeRestore(
      GetVolumeRestoreRequest request, StreamObserver<VolumeRestore> responseObserver) {
    Object response = responses.poll();
    if (response instanceof VolumeRestore) {
      requests.add(request);
      responseObserver.onNext(((VolumeRestore) 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 GetVolumeRestore, expected %s or %s",
                  response == null ? "null" : response.getClass().getName(),
                  VolumeRestore.class.getName(),
                  Exception.class.getName())));
    }
  }
}
