// 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.ArmApplicationHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ArmServiceTypeHealthPolicy;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ArmApplicationHealthPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ArmApplicationHealthPolicy model =
            BinaryData
                .fromString(
                    "{\"considerWarningAsError\":true,\"maxPercentUnhealthyDeployedApplications\":1368880432,\"defaultServiceTypeHealthPolicy\":{\"maxPercentUnhealthyServices\":618241707,\"maxPercentUnhealthyPartitionsPerService\":31117438,\"maxPercentUnhealthyReplicasPerPartition\":1777523774},\"serviceTypeHealthPolicyMap\":{\"ozuhkfp\":{\"maxPercentUnhealthyServices\":794147493,\"maxPercentUnhealthyPartitionsPerService\":583849936,\"maxPercentUnhealthyReplicasPerPartition\":1792717087},\"xl\":{\"maxPercentUnhealthyServices\":1369679233,\"maxPercentUnhealthyPartitionsPerService\":657936288,\"maxPercentUnhealthyReplicasPerPartition\":1295774959},\"uwaboekqvke\":{\"maxPercentUnhealthyServices\":522774709,\"maxPercentUnhealthyPartitionsPerService\":1856979158,\"maxPercentUnhealthyReplicasPerPartition\":1422945070},\"wyjsflhhcaalnjix\":{\"maxPercentUnhealthyServices\":643648278,\"maxPercentUnhealthyPartitionsPerService\":566883460,\"maxPercentUnhealthyReplicasPerPartition\":314739755}}}")
                .toObject(ArmApplicationHealthPolicy.class);
        Assertions.assertEquals(true, model.considerWarningAsError());
        Assertions.assertEquals(1368880432, model.maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(618241707, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyServices());
        Assertions
            .assertEquals(31117438, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyPartitionsPerService());
        Assertions
            .assertEquals(1777523774, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyReplicasPerPartition());
        Assertions
            .assertEquals(794147493, model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyServices());
        Assertions
            .assertEquals(
                583849936, model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyPartitionsPerService());
        Assertions
            .assertEquals(
                1792717087,
                model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyReplicasPerPartition());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ArmApplicationHealthPolicy model =
            new ArmApplicationHealthPolicy()
                .withConsiderWarningAsError(true)
                .withMaxPercentUnhealthyDeployedApplications(1368880432)
                .withDefaultServiceTypeHealthPolicy(
                    new ArmServiceTypeHealthPolicy()
                        .withMaxPercentUnhealthyServices(618241707)
                        .withMaxPercentUnhealthyPartitionsPerService(31117438)
                        .withMaxPercentUnhealthyReplicasPerPartition(1777523774))
                .withServiceTypeHealthPolicyMap(
                    mapOf(
                        "ozuhkfp",
                        new ArmServiceTypeHealthPolicy()
                            .withMaxPercentUnhealthyServices(794147493)
                            .withMaxPercentUnhealthyPartitionsPerService(583849936)
                            .withMaxPercentUnhealthyReplicasPerPartition(1792717087),
                        "xl",
                        new ArmServiceTypeHealthPolicy()
                            .withMaxPercentUnhealthyServices(1369679233)
                            .withMaxPercentUnhealthyPartitionsPerService(657936288)
                            .withMaxPercentUnhealthyReplicasPerPartition(1295774959),
                        "uwaboekqvke",
                        new ArmServiceTypeHealthPolicy()
                            .withMaxPercentUnhealthyServices(522774709)
                            .withMaxPercentUnhealthyPartitionsPerService(1856979158)
                            .withMaxPercentUnhealthyReplicasPerPartition(1422945070),
                        "wyjsflhhcaalnjix",
                        new ArmServiceTypeHealthPolicy()
                            .withMaxPercentUnhealthyServices(643648278)
                            .withMaxPercentUnhealthyPartitionsPerService(566883460)
                            .withMaxPercentUnhealthyReplicasPerPartition(314739755)));
        model = BinaryData.fromObject(model).toObject(ArmApplicationHealthPolicy.class);
        Assertions.assertEquals(true, model.considerWarningAsError());
        Assertions.assertEquals(1368880432, model.maxPercentUnhealthyDeployedApplications());
        Assertions.assertEquals(618241707, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyServices());
        Assertions
            .assertEquals(31117438, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyPartitionsPerService());
        Assertions
            .assertEquals(1777523774, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyReplicasPerPartition());
        Assertions
            .assertEquals(794147493, model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyServices());
        Assertions
            .assertEquals(
                583849936, model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyPartitionsPerService());
        Assertions
            .assertEquals(
                1792717087,
                model.serviceTypeHealthPolicyMap().get("ozuhkfp").maxPercentUnhealthyReplicasPerPartition());
    }

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