package com.netflix.spinnaker.clouddriver.google.compute;

import com.google.api.services.compute.model.Operation;
import com.netflix.spinnaker.clouddriver.data.task.Task;
import com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil;
import com.netflix.spinnaker.clouddriver.google.deploy.GoogleOperationPoller;
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials;

class RegionalOperation implements WaitableComputeOperation {

  private final Operation operation;
  private final GoogleNamedAccountCredentials credentials;
  private final GoogleOperationPoller poller;

  RegionalOperation(
      Operation operation,
      GoogleNamedAccountCredentials credentials,
      GoogleOperationPoller poller) {
    this.operation = operation;
    this.credentials = credentials;
    this.poller = poller;
  }

  @Override
  public Operation waitForDone(Task task, String phase) {
    return poller.waitForRegionalOperation(
        credentials.getCompute(),
        credentials.getProject(),
        operation.getRegion(),
        operation.getName(),
        /* timeoutSeconds= */ null,
        task,
        GCEUtil.getLocalName(operation.getTargetLink()),
        phase);
  }
}

@@ -1018,32 +1018,53 @@
 ject(),%0A        
+GCEUtil.getLocalName(
 operation.getReg
@@ -1068,16 +1068,17 @@
 Region()
+)
 ,%0A      

fix waiting on regional operations from the new MIG compute wrapper (#3718)