// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.workloads.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.workloads.fluent.models.SapApplicationServerInstanceInner;
import com.azure.resourcemanager.workloads.models.SapApplicationServerInstanceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SapApplicationServerInstanceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SapApplicationServerInstanceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"instanceNo\":\"ojgjrwjueiotwmc\",\"subnet\":\"tdx\",\"hostname\":\"txnrjaw\",\"kernelVersion\":\"wgxhn\",\"kernelPatch\":\"kxfbkpycgklwndn\",\"ipAddress\":\"dauwhvylwzbtd\",\"gatewayPort\":4861537181982868149,\"icmHttpPort\":3747533921605268466,\"icmHttpsPort\":3229287439431688526,\"vmDetails\":[],\"status\":\"Offline\",\"health\":\"Degraded\",\"provisioningState\":\"Failed\"},\"location\":\"ualupjmkh\",\"tags\":{\"lrbpbewtghfgbl\":\"bbcswsrtjri\"},\"id\":\"gw\",\"name\":\"zvlvqhjkbegib\",\"type\":\"nmxiebwwaloayqc\"}],\"nextLink\":\"rtzju\"}")
                .toObject(SapApplicationServerInstanceList.class);
        Assertions.assertEquals("ualupjmkh", model.value().get(0).location());
        Assertions.assertEquals("bbcswsrtjri", model.value().get(0).tags().get("lrbpbewtghfgbl"));
        Assertions.assertEquals("rtzju", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SapApplicationServerInstanceList model =
            new SapApplicationServerInstanceList()
                .withValue(
                    Arrays
                        .asList(
                            new SapApplicationServerInstanceInner()
                                .withLocation("ualupjmkh")
                                .withTags(mapOf("lrbpbewtghfgbl", "bbcswsrtjri"))))
                .withNextLink("rtzju");
        model = BinaryData.fromObject(model).toObject(SapApplicationServerInstanceList.class);
        Assertions.assertEquals("ualupjmkh", model.value().get(0).location());
        Assertions.assertEquals("bbcswsrtjri", model.value().get(0).tags().get("lrbpbewtghfgbl"));
        Assertions.assertEquals("rtzju", model.nextLink());
    }

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