// 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.fluent.models.ApplicationResourceUpdateProperties;
import com.azure.resourcemanager.servicefabric.models.ApplicationMetricDescription;
import com.azure.resourcemanager.servicefabric.models.ApplicationUpgradePolicy;
import com.azure.resourcemanager.servicefabric.models.ApplicationUserAssignedIdentity;
import com.azure.resourcemanager.servicefabric.models.ArmApplicationHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ArmRollingUpgradeMonitoringPolicy;
import com.azure.resourcemanager.servicefabric.models.ArmUpgradeFailureAction;
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 ApplicationResourceUpdatePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationResourceUpdateProperties model =
            BinaryData
                .fromString(
                    "{\"typeVersion\":\"qkrhahvljua\",\"parameters\":{\"ualaexqpvfadmw\":\"uhcdhm\",\"vgomz\":\"rcrgvx\",\"bnbbeldawkz\":\"fmisg\"},\"upgradePolicy\":{\"upgradeReplicaSetCheckTimeout\":\"io\",\"forceRestart\":true,\"rollingUpgradeMonitoringPolicy\":{\"failureAction\":\"Manual\",\"healthCheckWaitDuration\":\"uhashsfwx\",\"healthCheckStableDuration\":\"owzxcu\",\"healthCheckRetryTimeout\":\"cjooxdjebwpucwwf\",\"upgradeTimeout\":\"vbvmeu\",\"upgradeDomainTimeout\":\"ivyhzceuojgjrwju\"},\"applicationHealthPolicy\":{\"considerWarningAsError\":false,\"maxPercentUnhealthyDeployedApplications\":1580797213,\"serviceTypeHealthPolicyMap\":{}},\"upgradeMode\":\"UnmonitoredAuto\",\"recreateApplication\":false},\"minimumNodes\":7152724912237369631,\"maximumNodes\":4599897838164298418,\"removeApplicationCapacity\":false,\"metrics\":[{\"name\":\"gxhnisk\",\"maximumCapacity\":5666526648393096058,\"reservationCapacity\":611195536306035128,\"totalApplicationCapacity\":6671534158034285764},{\"name\":\"ndnhj\",\"maximumCapacity\":8256899685410293664,\"reservationCapacity\":4570571577423952755,\"totalApplicationCapacity\":8550144632866513257},{\"name\":\"tdhxujznbmpowuwp\",\"maximumCapacity\":4938464628745807464,\"reservationCapacity\":3036268179431574452,\"totalApplicationCapacity\":4253810910381406422}],\"managedIdentities\":[{\"name\":\"mkh\",\"principalId\":\"xobbcswsrt\"}]}")
                .toObject(ApplicationResourceUpdateProperties.class);
        Assertions.assertEquals("qkrhahvljua", model.typeVersion());
        Assertions.assertEquals("uhcdhm", model.parameters().get("ualaexqpvfadmw"));
        Assertions.assertEquals("io", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().forceRestart());
        Assertions
            .assertEquals(
                ArmUpgradeFailureAction.MANUAL, model.upgradePolicy().rollingUpgradeMonitoringPolicy().failureAction());
        Assertions
            .assertEquals(
                "uhashsfwx", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckWaitDuration());
        Assertions
            .assertEquals("owzxcu", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckStableDuration());
        Assertions
            .assertEquals(
                "cjooxdjebwpucwwf", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckRetryTimeout());
        Assertions.assertEquals("vbvmeu", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeTimeout());
        Assertions
            .assertEquals(
                "ivyhzceuojgjrwju", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeDomainTimeout());
        Assertions.assertEquals(false, model.upgradePolicy().applicationHealthPolicy().considerWarningAsError());
        Assertions
            .assertEquals(
                1580797213, model.upgradePolicy().applicationHealthPolicy().maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(RollingUpgradeMode.UNMONITORED_AUTO, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(false, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(7152724912237369631L, model.minimumNodes());
        Assertions.assertEquals(4599897838164298418L, model.maximumNodes());
        Assertions.assertEquals(false, model.removeApplicationCapacity());
        Assertions.assertEquals("gxhnisk", model.metrics().get(0).name());
        Assertions.assertEquals(5666526648393096058L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(611195536306035128L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(6671534158034285764L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("mkh", model.managedIdentities().get(0).name());
        Assertions.assertEquals("xobbcswsrt", model.managedIdentities().get(0).principalId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationResourceUpdateProperties model =
            new ApplicationResourceUpdateProperties()
                .withTypeVersion("qkrhahvljua")
                .withParameters(mapOf("ualaexqpvfadmw", "uhcdhm", "vgomz", "rcrgvx", "bnbbeldawkz", "fmisg"))
                .withUpgradePolicy(
                    new ApplicationUpgradePolicy()
                        .withUpgradeReplicaSetCheckTimeout("io")
                        .withForceRestart(true)
                        .withRollingUpgradeMonitoringPolicy(
                            new ArmRollingUpgradeMonitoringPolicy()
                                .withFailureAction(ArmUpgradeFailureAction.MANUAL)
                                .withHealthCheckWaitDuration("uhashsfwx")
                                .withHealthCheckStableDuration("owzxcu")
                                .withHealthCheckRetryTimeout("cjooxdjebwpucwwf")
                                .withUpgradeTimeout("vbvmeu")
                                .withUpgradeDomainTimeout("ivyhzceuojgjrwju"))
                        .withApplicationHealthPolicy(
                            new ArmApplicationHealthPolicy()
                                .withConsiderWarningAsError(false)
                                .withMaxPercentUnhealthyDeployedApplications(1580797213)
                                .withServiceTypeHealthPolicyMap(mapOf()))
                        .withUpgradeMode(RollingUpgradeMode.UNMONITORED_AUTO)
                        .withRecreateApplication(false))
                .withMinimumNodes(7152724912237369631L)
                .withMaximumNodes(4599897838164298418L)
                .withRemoveApplicationCapacity(false)
                .withMetrics(
                    Arrays
                        .asList(
                            new ApplicationMetricDescription()
                                .withName("gxhnisk")
                                .withMaximumCapacity(5666526648393096058L)
                                .withReservationCapacity(611195536306035128L)
                                .withTotalApplicationCapacity(6671534158034285764L),
                            new ApplicationMetricDescription()
                                .withName("ndnhj")
                                .withMaximumCapacity(8256899685410293664L)
                                .withReservationCapacity(4570571577423952755L)
                                .withTotalApplicationCapacity(8550144632866513257L),
                            new ApplicationMetricDescription()
                                .withName("tdhxujznbmpowuwp")
                                .withMaximumCapacity(4938464628745807464L)
                                .withReservationCapacity(3036268179431574452L)
                                .withTotalApplicationCapacity(4253810910381406422L)))
                .withManagedIdentities(
                    Arrays.asList(new ApplicationUserAssignedIdentity().withName("mkh").withPrincipalId("xobbcswsrt")));
        model = BinaryData.fromObject(model).toObject(ApplicationResourceUpdateProperties.class);
        Assertions.assertEquals("qkrhahvljua", model.typeVersion());
        Assertions.assertEquals("uhcdhm", model.parameters().get("ualaexqpvfadmw"));
        Assertions.assertEquals("io", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().forceRestart());
        Assertions
            .assertEquals(
                ArmUpgradeFailureAction.MANUAL, model.upgradePolicy().rollingUpgradeMonitoringPolicy().failureAction());
        Assertions
            .assertEquals(
                "uhashsfwx", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckWaitDuration());
        Assertions
            .assertEquals("owzxcu", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckStableDuration());
        Assertions
            .assertEquals(
                "cjooxdjebwpucwwf", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckRetryTimeout());
        Assertions.assertEquals("vbvmeu", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeTimeout());
        Assertions
            .assertEquals(
                "ivyhzceuojgjrwju", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeDomainTimeout());
        Assertions.assertEquals(false, model.upgradePolicy().applicationHealthPolicy().considerWarningAsError());
        Assertions
            .assertEquals(
                1580797213, model.upgradePolicy().applicationHealthPolicy().maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(RollingUpgradeMode.UNMONITORED_AUTO, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(false, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(7152724912237369631L, model.minimumNodes());
        Assertions.assertEquals(4599897838164298418L, model.maximumNodes());
        Assertions.assertEquals(false, model.removeApplicationCapacity());
        Assertions.assertEquals("gxhnisk", model.metrics().get(0).name());
        Assertions.assertEquals(5666526648393096058L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(611195536306035128L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(6671534158034285764L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("mkh", model.managedIdentities().get(0).name());
        Assertions.assertEquals("xobbcswsrt", 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;
    }
}
