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

public final class ClusterHealthPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterHealthPolicy model =
            BinaryData
                .fromString(
                    "{\"maxPercentUnhealthyNodes\":631357498,\"maxPercentUnhealthyApplications\":684639915,\"applicationHealthPolicies\":{\"ctazakljlahbcryf\":{\"defaultServiceTypeHealthPolicy\":{\"maxPercentUnhealthyServices\":1977100929},\"serviceTypeHealthPolicies\":{}},\"ygexpaojakhmsb\":{\"defaultServiceTypeHealthPolicy\":{\"maxPercentUnhealthyServices\":1276886479},\"serviceTypeHealthPolicies\":{}},\"evdphlxaol\":{\"defaultServiceTypeHealthPolicy\":{\"maxPercentUnhealthyServices\":510394239},\"serviceTypeHealthPolicies\":{}}}}")
                .toObject(ClusterHealthPolicy.class);
        Assertions.assertEquals(631357498, model.maxPercentUnhealthyNodes());
        Assertions.assertEquals(684639915, model.maxPercentUnhealthyApplications());
        Assertions
            .assertEquals(
                1977100929,
                model
                    .applicationHealthPolicies()
                    .get("ctazakljlahbcryf")
                    .defaultServiceTypeHealthPolicy()
                    .maxPercentUnhealthyServices());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterHealthPolicy model =
            new ClusterHealthPolicy()
                .withMaxPercentUnhealthyNodes(631357498)
                .withMaxPercentUnhealthyApplications(684639915)
                .withApplicationHealthPolicies(
                    mapOf(
                        "ctazakljlahbcryf",
                        new ApplicationHealthPolicy()
                            .withDefaultServiceTypeHealthPolicy(
                                new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(1977100929))
                            .withServiceTypeHealthPolicies(mapOf()),
                        "ygexpaojakhmsb",
                        new ApplicationHealthPolicy()
                            .withDefaultServiceTypeHealthPolicy(
                                new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(1276886479))
                            .withServiceTypeHealthPolicies(mapOf()),
                        "evdphlxaol",
                        new ApplicationHealthPolicy()
                            .withDefaultServiceTypeHealthPolicy(
                                new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(510394239))
                            .withServiceTypeHealthPolicies(mapOf())));
        model = BinaryData.fromObject(model).toObject(ClusterHealthPolicy.class);
        Assertions.assertEquals(631357498, model.maxPercentUnhealthyNodes());
        Assertions.assertEquals(684639915, model.maxPercentUnhealthyApplications());
        Assertions
            .assertEquals(
                1977100929,
                model
                    .applicationHealthPolicies()
                    .get("ctazakljlahbcryf")
                    .defaultServiceTypeHealthPolicy()
                    .maxPercentUnhealthyServices());
    }

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