<?php


/*
 * GENERATED CODE WARNING
 * This file was automatically generated - do not edit!
 */

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START notebooks_v1beta1_generated_NotebookService_SetInstanceMachineType_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Notebooks\V1beta1\Instance;
use Google\Cloud\Notebooks\V1beta1\NotebookServiceClient;
use Google\Rpc\Status;

/**
 * Updates the machine type of a single Instance.
 *
 * @param string $name        Format:
 *                            `projects/{project_id}/locations/{location}/instances/{instance_id}`
 * @param string $machineType The [Compute Engine machine
 *                            type](https://cloud.google.com/compute/docs/machine-types).
 */
function set_instance_machine_type_sample(string $name, string $machineType): void
{
    // Create a client.
    $notebookServiceClient = new NotebookServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $notebookServiceClient->setInstanceMachineType($name, $machineType);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Instance $response */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $name = '[NAME]';
    $machineType = '[MACHINE_TYPE]';

    set_instance_machine_type_sample($name, $machineType);
}
// [END notebooks_v1beta1_generated_NotebookService_SetInstanceMachineType_sync]
