// 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.ApplicationResourceProperties;
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 ApplicationResourcePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationResourceProperties model =
            BinaryData
                .fromString(
                    "{\"provisioningState\":\"nmic\",\"typeName\":\"vce\",\"typeVersion\":\"eil\",\"parameters\":{\"jfcn\":\"oty\",\"x\":\"bkc\",\"nv\":\"hbttkphyw\",\"qnermclfplphoxu\":\"t\"},\"upgradePolicy\":{\"upgradeReplicaSetCheckTimeout\":\"pabgyeps\",\"forceRestart\":true,\"rollingUpgradeMonitoringPolicy\":{\"failureAction\":\"Manual\",\"healthCheckWaitDuration\":\"gxywpmue\",\"healthCheckStableDuration\":\"jzwf\",\"healthCheckRetryTimeout\":\"q\",\"upgradeTimeout\":\"ids\",\"upgradeDomainTimeout\":\"onobglaocqx\"},\"applicationHealthPolicy\":{\"considerWarningAsError\":true,\"maxPercentUnhealthyDeployedApplications\":528280521,\"serviceTypeHealthPolicyMap\":{}},\"upgradeMode\":\"UnmonitoredAuto\",\"recreateApplication\":true},\"minimumNodes\":5036022727729954665,\"maximumNodes\":5697722366346871182,\"removeApplicationCapacity\":false,\"metrics\":[{\"name\":\"zntxhdz\",\"maximumCapacity\":1500394057372451894,\"reservationCapacity\":1353160377015146530,\"totalApplicationCapacity\":3107566314690039792},{\"name\":\"lhrxsbkyvpyc\",\"maximumCapacity\":1835147591912684740,\"reservationCapacity\":373365368946667415,\"totalApplicationCapacity\":6075974132031509292},{\"name\":\"uwbc\",\"maximumCapacity\":4066142529374885485,\"reservationCapacity\":5441826391386286828,\"totalApplicationCapacity\":5146449711958438241}],\"managedIdentities\":[{\"name\":\"jusrtslhspk\",\"principalId\":\"eemaofmxagkvtme\"}]}")
                .toObject(ApplicationResourceProperties.class);
        Assertions.assertEquals("eil", model.typeVersion());
        Assertions.assertEquals("oty", model.parameters().get("jfcn"));
        Assertions.assertEquals("pabgyeps", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().forceRestart());
        Assertions
            .assertEquals(
                ArmUpgradeFailureAction.MANUAL, model.upgradePolicy().rollingUpgradeMonitoringPolicy().failureAction());
        Assertions
            .assertEquals("gxywpmue", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckWaitDuration());
        Assertions
            .assertEquals("jzwf", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckStableDuration());
        Assertions.assertEquals("q", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckRetryTimeout());
        Assertions.assertEquals("ids", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeTimeout());
        Assertions
            .assertEquals("onobglaocqx", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeDomainTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().applicationHealthPolicy().considerWarningAsError());
        Assertions
            .assertEquals(
                528280521, model.upgradePolicy().applicationHealthPolicy().maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(RollingUpgradeMode.UNMONITORED_AUTO, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(true, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(5036022727729954665L, model.minimumNodes());
        Assertions.assertEquals(5697722366346871182L, model.maximumNodes());
        Assertions.assertEquals(false, model.removeApplicationCapacity());
        Assertions.assertEquals("zntxhdz", model.metrics().get(0).name());
        Assertions.assertEquals(1500394057372451894L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(1353160377015146530L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(3107566314690039792L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("jusrtslhspk", model.managedIdentities().get(0).name());
        Assertions.assertEquals("eemaofmxagkvtme", model.managedIdentities().get(0).principalId());
        Assertions.assertEquals("vce", model.typeName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationResourceProperties model =
            new ApplicationResourceProperties()
                .withTypeVersion("eil")
                .withParameters(mapOf("jfcn", "oty", "x", "bkc", "nv", "hbttkphyw", "qnermclfplphoxu", "t"))
                .withUpgradePolicy(
                    new ApplicationUpgradePolicy()
                        .withUpgradeReplicaSetCheckTimeout("pabgyeps")
                        .withForceRestart(true)
                        .withRollingUpgradeMonitoringPolicy(
                            new ArmRollingUpgradeMonitoringPolicy()
                                .withFailureAction(ArmUpgradeFailureAction.MANUAL)
                                .withHealthCheckWaitDuration("gxywpmue")
                                .withHealthCheckStableDuration("jzwf")
                                .withHealthCheckRetryTimeout("q")
                                .withUpgradeTimeout("ids")
                                .withUpgradeDomainTimeout("onobglaocqx"))
                        .withApplicationHealthPolicy(
                            new ArmApplicationHealthPolicy()
                                .withConsiderWarningAsError(true)
                                .withMaxPercentUnhealthyDeployedApplications(528280521)
                                .withServiceTypeHealthPolicyMap(mapOf()))
                        .withUpgradeMode(RollingUpgradeMode.UNMONITORED_AUTO)
                        .withRecreateApplication(true))
                .withMinimumNodes(5036022727729954665L)
                .withMaximumNodes(5697722366346871182L)
                .withRemoveApplicationCapacity(false)
                .withMetrics(
                    Arrays
                        .asList(
                            new ApplicationMetricDescription()
                                .withName("zntxhdz")
                                .withMaximumCapacity(1500394057372451894L)
                                .withReservationCapacity(1353160377015146530L)
                                .withTotalApplicationCapacity(3107566314690039792L),
                            new ApplicationMetricDescription()
                                .withName("lhrxsbkyvpyc")
                                .withMaximumCapacity(1835147591912684740L)
                                .withReservationCapacity(373365368946667415L)
                                .withTotalApplicationCapacity(6075974132031509292L),
                            new ApplicationMetricDescription()
                                .withName("uwbc")
                                .withMaximumCapacity(4066142529374885485L)
                                .withReservationCapacity(5441826391386286828L)
                                .withTotalApplicationCapacity(5146449711958438241L)))
                .withManagedIdentities(
                    Arrays
                        .asList(
                            new ApplicationUserAssignedIdentity()
                                .withName("jusrtslhspk")
                                .withPrincipalId("eemaofmxagkvtme")))
                .withTypeName("vce");
        model = BinaryData.fromObject(model).toObject(ApplicationResourceProperties.class);
        Assertions.assertEquals("eil", model.typeVersion());
        Assertions.assertEquals("oty", model.parameters().get("jfcn"));
        Assertions.assertEquals("pabgyeps", model.upgradePolicy().upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().forceRestart());
        Assertions
            .assertEquals(
                ArmUpgradeFailureAction.MANUAL, model.upgradePolicy().rollingUpgradeMonitoringPolicy().failureAction());
        Assertions
            .assertEquals("gxywpmue", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckWaitDuration());
        Assertions
            .assertEquals("jzwf", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckStableDuration());
        Assertions.assertEquals("q", model.upgradePolicy().rollingUpgradeMonitoringPolicy().healthCheckRetryTimeout());
        Assertions.assertEquals("ids", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeTimeout());
        Assertions
            .assertEquals("onobglaocqx", model.upgradePolicy().rollingUpgradeMonitoringPolicy().upgradeDomainTimeout());
        Assertions.assertEquals(true, model.upgradePolicy().applicationHealthPolicy().considerWarningAsError());
        Assertions
            .assertEquals(
                528280521, model.upgradePolicy().applicationHealthPolicy().maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(RollingUpgradeMode.UNMONITORED_AUTO, model.upgradePolicy().upgradeMode());
        Assertions.assertEquals(true, model.upgradePolicy().recreateApplication());
        Assertions.assertEquals(5036022727729954665L, model.minimumNodes());
        Assertions.assertEquals(5697722366346871182L, model.maximumNodes());
        Assertions.assertEquals(false, model.removeApplicationCapacity());
        Assertions.assertEquals("zntxhdz", model.metrics().get(0).name());
        Assertions.assertEquals(1500394057372451894L, model.metrics().get(0).maximumCapacity());
        Assertions.assertEquals(1353160377015146530L, model.metrics().get(0).reservationCapacity());
        Assertions.assertEquals(3107566314690039792L, model.metrics().get(0).totalApplicationCapacity());
        Assertions.assertEquals("jusrtslhspk", model.managedIdentities().get(0).name());
        Assertions.assertEquals("eemaofmxagkvtme", model.managedIdentities().get(0).principalId());
        Assertions.assertEquals("vce", model.typeName());
    }

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