// 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.fluent.models.PrivateEndpointConnectionInner;
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 com.azure.resourcemanager.deviceupdate.models.UserAssignedIdentity;
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 AccountInnerTests {
    @Test
    public void testDeserialize() {
        AccountInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Creating\",\"hostName\":\"hjxri\",\"publicNetworkAccess\":\"Disabled\",\"privateEndpointConnections\":[{\"id\":\"ktsizntocipaou\",\"name\":\"jpsq\",\"type\":\"cmpoyfdkfogkny\"},{\"id\":\"ofjdde\",\"name\":\"s\",\"type\":\"deupewnwrei\"}],\"sku\":\"Free\",\"locations\":[{\"name\":\"usarhmofc\",\"role\":\"Primary\"},{\"name\":\"yurkdtmlxhekuksj\",\"role\":\"Failover\"},{\"name\":\"cdm\",\"role\":\"Failover\"}]},\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"uxzdxtay\":{},\"m\":{}}},\"location\":\"hfpmrqobmtukknr\",\"tags\":{\"mglzufcy\":\"ihfxtijbpzvgnwzs\",\"ufhfcbjysa\":\"kohdbiha\"},\"id\":\"ithxqhabifpi\",\"name\":\"xwczbyscnp\",\"type\":\"x\"}")
                .toObject(AccountInner.class);
        Assertions.assertEquals("hfpmrqobmtukknr", model.location());
        Assertions.assertEquals("ihfxtijbpzvgnwzs", model.tags().get("mglzufcy"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(Sku.FREE, model.sku());
    }

    @Test
    public void testSerialize() {
        AccountInner model =
            new AccountInner()
                .withLocation("hfpmrqobmtukknr")
                .withTags(mapOf("mglzufcy", "ihfxtijbpzvgnwzs", "ufhfcbjysa", "kohdbiha"))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf("uxzdxtay", new UserAssignedIdentity(), "m", new UserAssignedIdentity())))
                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                .withPrivateEndpointConnections(
                    Arrays.asList(new PrivateEndpointConnectionInner(), new PrivateEndpointConnectionInner()))
                .withSku(Sku.FREE);
        model = BinaryData.fromObject(model).toObject(AccountInner.class);
        Assertions.assertEquals("hfpmrqobmtukknr", model.location());
        Assertions.assertEquals("ihfxtijbpzvgnwzs", model.tags().get("mglzufcy"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(Sku.FREE, model.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;
    }
}
