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

package com.azure.resourcemanager.deviceupdate.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.deviceupdate.fluent.models.AccountInner;
import com.azure.resourcemanager.deviceupdate.models.AccountList;
import com.azure.resourcemanager.deviceupdate.models.ManagedServiceIdentity;
import com.azure.resourcemanager.deviceupdate.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.deviceupdate.models.PublicNetworkAccess;
import com.azure.resourcemanager.deviceupdate.models.Sku;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class AccountListTests {
    @Test
    public void testDeserialize() {
        AccountList model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"ycm\",\"value\":[{\"properties\":{\"provisioningState\":\"Canceled\",\"hostName\":\"xbmtqioqjz\",\"publicNetworkAccess\":\"Enabled\",\"privateEndpointConnections\":[],\"sku\":\"Free\",\"locations\":[]},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"location\":\"izhwlrxy\",\"tags\":{\"obcu\":\"oqijgkdmbpaz\",\"qgn\":\"pdznrbtcqqjnqgl\"},\"id\":\"foooj\",\"name\":\"wifsq\",\"type\":\"saagdf\"}]}")
                .toObject(AccountList.class);
        Assertions.assertEquals("ycm", model.nextLink());
        Assertions.assertEquals("izhwlrxy", model.value().get(0).location());
        Assertions.assertEquals("oqijgkdmbpaz", model.value().get(0).tags().get("obcu"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(Sku.FREE, model.value().get(0).sku());
    }

    @Test
    public void testSerialize() {
        AccountList model =
            new AccountList()
                .withNextLink("ycm")
                .withValue(
                    Arrays
                        .asList(
                            new AccountInner()
                                .withLocation("izhwlrxy")
                                .withTags(mapOf("obcu", "oqijgkdmbpaz", "qgn", "pdznrbtcqqjnqgl"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withPrivateEndpointConnections(Arrays.asList())
                                .withSku(Sku.FREE)));
        model = BinaryData.fromObject(model).toObject(AccountList.class);
        Assertions.assertEquals("ycm", model.nextLink());
        Assertions.assertEquals("izhwlrxy", model.value().get(0).location());
        Assertions.assertEquals("oqijgkdmbpaz", model.value().get(0).tags().get("obcu"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(Sku.FREE, model.value().get(0).sku());
    }

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