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

public final class ApplicationDeltaHealthPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationDeltaHealthPolicy model =
            BinaryData
                .fromString(
                    "{\"defaultServiceTypeDeltaHealthPolicy\":{\"maxPercentDeltaUnhealthyServices\":956108076},\"serviceTypeDeltaHealthPolicies\":{\"mihe\":{\"maxPercentDeltaUnhealthyServices\":827066207},\"arxzxtheot\":{\"maxPercentDeltaUnhealthyServices\":1134351284},\"vyevcciqi\":{\"maxPercentDeltaUnhealthyServices\":1852537816},\"un\":{\"maxPercentDeltaUnhealthyServices\":720964194}}}")
                .toObject(ApplicationDeltaHealthPolicy.class);
        Assertions
            .assertEquals(956108076, model.defaultServiceTypeDeltaHealthPolicy().maxPercentDeltaUnhealthyServices());
        Assertions
            .assertEquals(
                827066207, model.serviceTypeDeltaHealthPolicies().get("mihe").maxPercentDeltaUnhealthyServices());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationDeltaHealthPolicy model =
            new ApplicationDeltaHealthPolicy()
                .withDefaultServiceTypeDeltaHealthPolicy(
                    new ServiceTypeDeltaHealthPolicy().withMaxPercentDeltaUnhealthyServices(956108076))
                .withServiceTypeDeltaHealthPolicies(
                    mapOf(
                        "mihe",
                        new ServiceTypeDeltaHealthPolicy().withMaxPercentDeltaUnhealthyServices(827066207),
                        "arxzxtheot",
                        new ServiceTypeDeltaHealthPolicy().withMaxPercentDeltaUnhealthyServices(1134351284),
                        "vyevcciqi",
                        new ServiceTypeDeltaHealthPolicy().withMaxPercentDeltaUnhealthyServices(1852537816),
                        "un",
                        new ServiceTypeDeltaHealthPolicy().withMaxPercentDeltaUnhealthyServices(720964194)));
        model = BinaryData.fromObject(model).toObject(ApplicationDeltaHealthPolicy.class);
        Assertions
            .assertEquals(956108076, model.defaultServiceTypeDeltaHealthPolicy().maxPercentDeltaUnhealthyServices());
        Assertions
            .assertEquals(
                827066207, model.serviceTypeDeltaHealthPolicies().get("mihe").maxPercentDeltaUnhealthyServices());
    }

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