// 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.SapVirtualInstanceInner;
import com.azure.resourcemanager.workloads.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.workloads.models.SapEnvironmentType;
import com.azure.resourcemanager.workloads.models.SapProductType;
import com.azure.resourcemanager.workloads.models.SapVirtualInstanceList;
import com.azure.resourcemanager.workloads.models.UserAssignedServiceIdentity;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SapVirtualInstanceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SapVirtualInstanceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"properties\":{\"environment\":\"NonProd\",\"sapProduct\":\"ECC\",\"status\":\"Stopping\",\"health\":\"Unknown\",\"state\":\"DiscoveryInProgress\",\"provisioningState\":\"Failed\"},\"location\":\"jaeq\",\"tags\":{\"tnb\":\"jbasvmsmjqulngs\",\"wrljdouskc\":\"bkzgcwrwclx\"},\"id\":\"vkocrcjdkwtn\",\"name\":\"xbnjbiksq\",\"type\":\"gls\"},{\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"environment\":\"Prod\",\"sapProduct\":\"S4HANA\",\"status\":\"SoftShutdown\",\"health\":\"Unhealthy\",\"state\":\"RegistrationComplete\",\"provisioningState\":\"Failed\"},\"location\":\"eebvmgxsab\",\"tags\":{\"c\":\"duuji\",\"dhkrwpdappdsbdk\":\"czdzev\",\"nhutjeltmrldhugj\":\"wrwjfeu\",\"ablgphuticndvk\":\"zdatqxhocdg\"},\"id\":\"ozwyiftyhxhuro\",\"name\":\"ftyxolniw\",\"type\":\"wcukjfkgiawxk\"},{\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"properties\":{\"environment\":\"Prod\",\"sapProduct\":\"ECC\",\"status\":\"Starting\",\"health\":\"Unknown\",\"state\":\"InfrastructureDeploymentFailed\",\"provisioningState\":\"Updating\"},\"location\":\"hsgcbacphejkot\",\"tags\":{\"zndlikwy\":\"gou\",\"bmadgak\":\"kgfg\"},\"id\":\"qsrxybzqqed\",\"name\":\"ytb\",\"type\":\"iqfouflmmnkz\"}],\"nextLink\":\"odmgl\"}")
                .toObject(SapVirtualInstanceList.class);
        Assertions.assertEquals("jaeq", model.value().get(0).location());
        Assertions.assertEquals("jbasvmsmjqulngs", model.value().get(0).tags().get("tnb"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(SapEnvironmentType.NON_PROD, model.value().get(0).environment());
        Assertions.assertEquals(SapProductType.ECC, model.value().get(0).sapProduct());
        Assertions.assertEquals("odmgl", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SapVirtualInstanceList model =
            new SapVirtualInstanceList()
                .withValue(
                    Arrays
                        .asList(
                            new SapVirtualInstanceInner()
                                .withLocation("jaeq")
                                .withTags(mapOf("tnb", "jbasvmsmjqulngs", "wrljdouskc", "bkzgcwrwclx"))
                                .withIdentity(
                                    new UserAssignedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withEnvironment(SapEnvironmentType.NON_PROD)
                                .withSapProduct(SapProductType.ECC),
                            new SapVirtualInstanceInner()
                                .withLocation("eebvmgxsab")
                                .withTags(
                                    mapOf(
                                        "c",
                                        "duuji",
                                        "dhkrwpdappdsbdk",
                                        "czdzev",
                                        "nhutjeltmrldhugj",
                                        "wrwjfeu",
                                        "ablgphuticndvk",
                                        "zdatqxhocdg"))
                                .withIdentity(
                                    new UserAssignedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withEnvironment(SapEnvironmentType.PROD)
                                .withSapProduct(SapProductType.S4HANA),
                            new SapVirtualInstanceInner()
                                .withLocation("hsgcbacphejkot")
                                .withTags(mapOf("zndlikwy", "gou", "bmadgak", "kgfg"))
                                .withIdentity(
                                    new UserAssignedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withEnvironment(SapEnvironmentType.PROD)
                                .withSapProduct(SapProductType.ECC)))
                .withNextLink("odmgl");
        model = BinaryData.fromObject(model).toObject(SapVirtualInstanceList.class);
        Assertions.assertEquals("jaeq", model.value().get(0).location());
        Assertions.assertEquals("jbasvmsmjqulngs", model.value().get(0).tags().get("tnb"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(SapEnvironmentType.NON_PROD, model.value().get(0).environment());
        Assertions.assertEquals(SapProductType.ECC, model.value().get(0).sapProduct());
        Assertions.assertEquals("odmgl", 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;
    }
}
