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

package com.azure.resourcemanager.appplatform.generated;

import com.azure.core.util.Context;
import com.azure.resourcemanager.appplatform.fluent.models.AppResourceInner;
import com.azure.resourcemanager.appplatform.models.AppResourceProperties;
import com.azure.resourcemanager.appplatform.models.AppVNetAddons;
import com.azure.resourcemanager.appplatform.models.AzureFileVolume;
import com.azure.resourcemanager.appplatform.models.CustomPersistentDiskResource;
import com.azure.resourcemanager.appplatform.models.ManagedIdentityProperties;
import com.azure.resourcemanager.appplatform.models.ManagedIdentityType;
import com.azure.resourcemanager.appplatform.models.PersistentDisk;
import com.azure.resourcemanager.appplatform.models.TemporaryDisk;
import com.azure.resourcemanager.appplatform.models.UserAssignedManagedIdentity;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/** Samples for Apps Update. */
public final class AppsUpdateSamples {
    /*
     * x-ms-original-file: specification/appplatform/resource-manager/Microsoft.AppPlatform/stable/2022-12-01/examples/Apps_Update_VNetInjection.json
     */
    /**
     * Sample code: Apps_Update_VNetInjection.
     *
     * @param azure The entry point for accessing resource management APIs in Azure.
     */
    public static void appsUpdateVNetInjection(com.azure.resourcemanager.AzureResourceManager azure) {
        azure
            .springServices()
            .manager()
            .serviceClient()
            .getApps()
            .update(
                "myResourceGroup",
                "myservice",
                "myapp",
                new AppResourceInner()
                    .withProperties(
                        new AppResourceProperties()
                            .withPublicProperty(true)
                            .withHttpsOnly(false)
                            .withTemporaryDisk(new TemporaryDisk().withSizeInGB(2).withMountPath("/mytemporarydisk"))
                            .withPersistentDisk(new PersistentDisk().withSizeInGB(2).withMountPath("/mypersistentdisk"))
                            .withCustomPersistentDisks(
                                Arrays
                                    .asList(
                                        new CustomPersistentDiskResource()
                                            .withCustomPersistentDiskProperties(
                                                new AzureFileVolume()
                                                    .withMountPath("/mypath1/mypath2")
                                                    .withMountOptions(Arrays.asList())
                                                    .withShareName("myFileShare"))
                                            .withStorageId("myASCStorageID")))
                            .withEnableEndToEndTls(false)
                            .withVnetAddons(new AppVNetAddons().withPublicEndpoint(true)))
                    .withIdentity(
                        new ManagedIdentityProperties()
                            .withType(ManagedIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                            .withUserAssignedIdentities(
                                mapOf(
                                    "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1",
                                    new UserAssignedManagedIdentity(),
                                    "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2",
                                    new UserAssignedManagedIdentity())))
                    .withLocation("eastus"),
                Context.NONE);
    }

    /*
     * x-ms-original-file: specification/appplatform/resource-manager/Microsoft.AppPlatform/stable/2022-12-01/examples/Apps_Update.json
     */
    /**
     * Sample code: Apps_Update.
     *
     * @param azure The entry point for accessing resource management APIs in Azure.
     */
    public static void appsUpdate(com.azure.resourcemanager.AzureResourceManager azure) {
        azure
            .springServices()
            .manager()
            .serviceClient()
            .getApps()
            .update(
                "myResourceGroup",
                "myservice",
                "myapp",
                new AppResourceInner()
                    .withProperties(
                        new AppResourceProperties()
                            .withPublicProperty(true)
                            .withHttpsOnly(false)
                            .withTemporaryDisk(new TemporaryDisk().withSizeInGB(2).withMountPath("/mytemporarydisk"))
                            .withPersistentDisk(new PersistentDisk().withSizeInGB(2).withMountPath("/mypersistentdisk"))
                            .withCustomPersistentDisks(
                                Arrays
                                    .asList(
                                        new CustomPersistentDiskResource()
                                            .withCustomPersistentDiskProperties(
                                                new AzureFileVolume()
                                                    .withMountPath("/mypath1/mypath2")
                                                    .withMountOptions(Arrays.asList())
                                                    .withShareName("myFileShare"))
                                            .withStorageId("myASCStorageID")))
                            .withEnableEndToEndTls(false))
                    .withIdentity(
                        new ManagedIdentityProperties()
                            .withType(ManagedIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                            .withUserAssignedIdentities(
                                mapOf(
                                    "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1",
                                    new UserAssignedManagedIdentity(),
                                    "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2",
                                    new UserAssignedManagedIdentity())))
                    .withLocation("eastus"),
                Context.NONE);
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
