// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.batch.generated;

import com.azure.core.util.Context;
import com.azure.resourcemanager.batch.models.ApplicationPackageReference;
import com.azure.resourcemanager.batch.models.AutoScaleSettings;
import com.azure.resourcemanager.batch.models.CertificateReference;
import com.azure.resourcemanager.batch.models.CertificateStoreLocation;
import com.azure.resourcemanager.batch.models.ComputeNodeDeallocationOption;
import com.azure.resourcemanager.batch.models.FixedScaleSettings;
import com.azure.resourcemanager.batch.models.MetadataItem;
import com.azure.resourcemanager.batch.models.NodeCommunicationMode;
import com.azure.resourcemanager.batch.models.Pool;
import com.azure.resourcemanager.batch.models.ScaleSettings;
import com.azure.resourcemanager.batch.models.StartTask;
import java.time.Duration;
import java.util.Arrays;

/** Samples for Pool Update. */
public final class PoolUpdateSamples {
    /*
     * x-ms-original-file: specification/batch/resource-manager/Microsoft.Batch/stable/2022-10-01/examples/PoolUpdate_EnableAutoScale.json
     */
    /**
     * Sample code: UpdatePool - Enable Autoscale.
     *
     * @param manager Entry point to BatchManager.
     */
    public static void updatePoolEnableAutoscale(com.azure.resourcemanager.batch.BatchManager manager) {
        Pool resource =
            manager
                .pools()
                .getWithResponse("default-azurebatch-japaneast", "sampleacct", "testpool", Context.NONE)
                .getValue();
        resource
            .update()
            .withScaleSettings(
                new ScaleSettings().withAutoScale(new AutoScaleSettings().withFormula("$TargetDedicatedNodes=34")))
            .apply();
    }

    /*
     * x-ms-original-file: specification/batch/resource-manager/Microsoft.Batch/stable/2022-10-01/examples/PoolUpdate_RemoveStartTask.json
     */
    /**
     * Sample code: UpdatePool - Remove Start Task.
     *
     * @param manager Entry point to BatchManager.
     */
    public static void updatePoolRemoveStartTask(com.azure.resourcemanager.batch.BatchManager manager) {
        Pool resource =
            manager
                .pools()
                .getWithResponse("default-azurebatch-japaneast", "sampleacct", "testpool", Context.NONE)
                .getValue();
        resource.update().withStartTask(new StartTask()).apply();
    }

    /*
     * x-ms-original-file: specification/batch/resource-manager/Microsoft.Batch/stable/2022-10-01/examples/PoolUpdate_ResizePool.json
     */
    /**
     * Sample code: UpdatePool - Resize Pool.
     *
     * @param manager Entry point to BatchManager.
     */
    public static void updatePoolResizePool(com.azure.resourcemanager.batch.BatchManager manager) {
        Pool resource =
            manager
                .pools()
                .getWithResponse("default-azurebatch-japaneast", "sampleacct", "testpool", Context.NONE)
                .getValue();
        resource
            .update()
            .withScaleSettings(
                new ScaleSettings()
                    .withFixedScale(
                        new FixedScaleSettings()
                            .withResizeTimeout(Duration.parse("PT8M"))
                            .withTargetDedicatedNodes(5)
                            .withTargetLowPriorityNodes(0)
                            .withNodeDeallocationOption(ComputeNodeDeallocationOption.TASK_COMPLETION)))
            .apply();
    }

    /*
     * x-ms-original-file: specification/batch/resource-manager/Microsoft.Batch/stable/2022-10-01/examples/PoolUpdate_OtherProperties.json
     */
    /**
     * Sample code: UpdatePool - Other Properties.
     *
     * @param manager Entry point to BatchManager.
     */
    public static void updatePoolOtherProperties(com.azure.resourcemanager.batch.BatchManager manager) {
        Pool resource =
            manager
                .pools()
                .getWithResponse("default-azurebatch-japaneast", "sampleacct", "testpool", Context.NONE)
                .getValue();
        resource
            .update()
            .withMetadata(Arrays.asList(new MetadataItem().withName("key1").withValue("value1")))
            .withCertificates(
                Arrays
                    .asList(
                        new CertificateReference()
                            .withId(
                                "/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/pools/testpool/certificates/sha1-1234567")
                            .withStoreLocation(CertificateStoreLocation.LOCAL_MACHINE)
                            .withStoreName("MY")))
            .withApplicationPackages(
                Arrays
                    .asList(
                        new ApplicationPackageReference()
                            .withId(
                                "/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/pools/testpool/applications/app_1234"),
                        new ApplicationPackageReference()
                            .withId(
                                "/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/pools/testpool/applications/app_5678")
                            .withVersion("1.0")))
            .withTargetNodeCommunicationMode(NodeCommunicationMode.SIMPLIFIED)
            .apply();
    }
}
