// 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.ServiceTypeHealthPolicy;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ApplicationHealthPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationHealthPolicy model =
            BinaryData
                .fromString(
                    "{\"defaultServiceTypeHealthPolicy\":{\"maxPercentUnhealthyServices\":578472109},\"serviceTypeHealthPolicies\":{\"bpf\":{\"maxPercentUnhealthyServices\":607055364},\"inzgvfcj\":{\"maxPercentUnhealthyServices\":257181558},\"oxxjtfelluwf\":{\"maxPercentUnhealthyServices\":1821850933}}}")
                .toObject(ApplicationHealthPolicy.class);
        Assertions.assertEquals(578472109, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyServices());
        Assertions.assertEquals(607055364, model.serviceTypeHealthPolicies().get("bpf").maxPercentUnhealthyServices());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationHealthPolicy model =
            new ApplicationHealthPolicy()
                .withDefaultServiceTypeHealthPolicy(
                    new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(578472109))
                .withServiceTypeHealthPolicies(
                    mapOf(
                        "bpf",
                        new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(607055364),
                        "inzgvfcj",
                        new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(257181558),
                        "oxxjtfelluwf",
                        new ServiceTypeHealthPolicy().withMaxPercentUnhealthyServices(1821850933)));
        model = BinaryData.fromObject(model).toObject(ApplicationHealthPolicy.class);
        Assertions.assertEquals(578472109, model.defaultServiceTypeHealthPolicy().maxPercentUnhealthyServices());
        Assertions.assertEquals(607055364, model.serviceTypeHealthPolicies().get("bpf").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;
    }
}
