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

package com.azure.resourcemanager.servicefabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicefabric.models.ApplicationMetricDescription;
import com.azure.resourcemanager.servicefabric.models.ApplicationResourceUpdate;
import com.azure.resourcemanager.servicefabric.models.ApplicationUpgradePolicy;
import com.azure.resourcemanager.servicefabric.models.ApplicationUserAssignedIdentity;
import com.azure.resourcemanager.servicefabric.models.RollingUpgradeMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ApplicationResourceUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationResourceUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"typeVersion\":\"laulppg\",\"parameters\":{\"igvpgylg\":\"pnapnyiropuh\",\"medjvcslynqwwncw\":\"git\",\"pkteo\":\"zhxgktrmgucn\",\"pfqbuaceopzf\":\"llwptfdy\"},\"upgradePolicy\":{\"upgradeReplicaSetCheckTimeout\":\"huaoppp\",\"forceRestart\":false,\"upgradeMode\":\"Monitored\",\"recreateApplication\":true},\"minimumNodes\":4786890397912480430,\"maximumNodes\":5358059315050438852,\"removeApplicationCapacity\":true,\"metrics\":[{\"name\":\"dmoizpostmg\",\"maximumCapacity\":4576666657495905639,\"reservationCapacity\":686472769519617927,\"totalApplicationCapacity\":6463031828176764162},{\"name\":\"hhkxbp\",\"maximumCapacity\":8074620873162996793,\"reservationCapacity\":2129707645573311231,\"totalApplicationCapacity\":1101297438428430971}],\"managedIdentities\":[{\"name\":\"u\",\"principalId\":\"ivkrtsw\"},{\"name\":\"xqzvszjfa\",\"principalId\":\"vjfdx\"},{\"name\":\"ivetvtcq\",\"principalId\":\"qtdo\"},{\"name\":\"mcbxvwvxysl\",\"principalId\":\"bhsfxob\"}]},\"location\":\"tkblmpewww\",\"tags\":{\"sbfov\":\"rvrnsvshqjohxc\",\"birx\":\"srruvwbhsqfsubcg\"},\"etag\":\"ybsrfbjfdtwss\",\"id\":\"ftpvjzbexil\",\"name\":\"znfqqnvwpmqtar\",\"type\":\"oujmkcjhwqytj\"}")
                .toObject(ApplicationResourceUpdate.class);
        Assertions.assertEquals("tkblmpewww", model.location());
        Assertions.assertEquals("rvrnsvshqjohxc", model.tags().get("sbfov"));
        Assertions.assertEquals("laulppg", model.typeVersion());
        Assertions.assertEquals("pnapnyiropuh", model.parameters().get("igvpgylg"));
        Assertions.assertEquals("huaoppp", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(false, model.upgradePolicy().forceRestart());
        Assertions.assertEquals(RollingUpgradeMode.MONITORED, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(true, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(4786890397912480430L, model.minimumNodes());
        Assertions.assertEquals(5358059315050438852L, model.maximumNodes());
        Assertions.assertEquals(true, model.removeApplicationCapacity());
        Assertions.assertEquals("dmoizpostmg", model.metrics().get(0).name());
        Assertions.assertEquals(4576666657495905639L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(686472769519617927L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(6463031828176764162L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("u", model.managedIdentities().get(0).name());
        Assertions.assertEquals("ivkrtsw", model.managedIdentities().get(0).principalId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationResourceUpdate model =
            new ApplicationResourceUpdate()
                .withLocation("tkblmpewww")
                .withTags(mapOf("sbfov", "rvrnsvshqjohxc", "birx", "srruvwbhsqfsubcg"))
                .withTypeVersion("laulppg")
                .withParameters(
                    mapOf(
                        "igvpgylg",
                        "pnapnyiropuh",
                        "medjvcslynqwwncw",
                        "git",
                        "pkteo",
                        "zhxgktrmgucn",
                        "pfqbuaceopzf",
                        "llwptfdy"))
                .withUpgradePolicy(
                    new ApplicationUpgradePolicy()
                        .withUpgradeReplicaSetCheckTimeout("huaoppp")
                        .withForceRestart(false)
                        .withUpgradeMode(RollingUpgradeMode.MONITORED)
                        .withRecreateApplication(true))
                .withMinimumNodes(4786890397912480430L)
                .withMaximumNodes(5358059315050438852L)
                .withRemoveApplicationCapacity(true)
                .withMetrics(
                    Arrays
                        .asList(
                            new ApplicationMetricDescription()
                                .withName("dmoizpostmg")
                                .withMaximumCapacity(4576666657495905639L)
                                .withReservationCapacity(686472769519617927L)
                                .withTotalApplicationCapacity(6463031828176764162L),
                            new ApplicationMetricDescription()
                                .withName("hhkxbp")
                                .withMaximumCapacity(8074620873162996793L)
                                .withReservationCapacity(2129707645573311231L)
                                .withTotalApplicationCapacity(1101297438428430971L)))
                .withManagedIdentities(
                    Arrays
                        .asList(
                            new ApplicationUserAssignedIdentity().withName("u").withPrincipalId("ivkrtsw"),
                            new ApplicationUserAssignedIdentity().withName("xqzvszjfa").withPrincipalId("vjfdx"),
                            new ApplicationUserAssignedIdentity().withName("ivetvtcq").withPrincipalId("qtdo"),
                            new ApplicationUserAssignedIdentity().withName("mcbxvwvxysl").withPrincipalId("bhsfxob")));
        model = BinaryData.fromObject(model).toObject(ApplicationResourceUpdate.class);
        Assertions.assertEquals("tkblmpewww", model.location());
        Assertions.assertEquals("rvrnsvshqjohxc", model.tags().get("sbfov"));
        Assertions.assertEquals("laulppg", model.typeVersion());
        Assertions.assertEquals("pnapnyiropuh", model.parameters().get("igvpgylg"));
        Assertions.assertEquals("huaoppp", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(false, model.upgradePolicy().forceRestart());
        Assertions.assertEquals(RollingUpgradeMode.MONITORED, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(true, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(4786890397912480430L, model.minimumNodes());
        Assertions.assertEquals(5358059315050438852L, model.maximumNodes());
        Assertions.assertEquals(true, model.removeApplicationCapacity());
        Assertions.assertEquals("dmoizpostmg", model.metrics().get(0).name());
        Assertions.assertEquals(4576666657495905639L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(686472769519617927L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(6463031828176764162L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("u", model.managedIdentities().get(0).name());
        Assertions.assertEquals("ivkrtsw", model.managedIdentities().get(0).principalId());
    }

    @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;
    }
}
