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

package com.azure.resourcemanager.iothub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.iothub.fluent.models.IotHubDescriptionInner;
import com.azure.resourcemanager.iothub.models.ArmIdentity;
import com.azure.resourcemanager.iothub.models.Capabilities;
import com.azure.resourcemanager.iothub.models.IotHubDescriptionListResult;
import com.azure.resourcemanager.iothub.models.IotHubProperties;
import com.azure.resourcemanager.iothub.models.IotHubSku;
import com.azure.resourcemanager.iothub.models.IotHubSkuInfo;
import com.azure.resourcemanager.iothub.models.IpVersion;
import com.azure.resourcemanager.iothub.models.PublicNetworkAccess;
import com.azure.resourcemanager.iothub.models.ResourceIdentityType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IotHubDescriptionListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IotHubDescriptionListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"etag\":\"gnxytxhpzxbz\",\"properties\":{\"authorizationPolicies\":[],\"disableLocalAuth\":false,\"disableDeviceSAS\":true,\"disableModuleSAS\":true,\"restrictOutboundNetworkAccess\":true,\"allowedFqdnList\":[],\"publicNetworkAccess\":\"Enabled\",\"ipFilterRules\":[],\"minTlsVersion\":\"iklbbovpl\",\"privateEndpointConnections\":[],\"provisioningState\":\"hvgyuguosvmk\",\"state\":\"sxqu\",\"hostName\":\"fpl\",\"eventHubEndpoints\":{},\"storageEndpoints\":{},\"messagingEndpoints\":{},\"enableFileUploadNotifications\":false,\"comments\":\"kde\",\"features\":\"DeviceManagement\",\"locations\":[],\"enableDataResidency\":true,\"ipVersion\":\"ipv4ipv6\"},\"sku\":{\"name\":\"S3\",\"tier\":\"Free\",\"capacity\":8474633220472193573},\"identity\":{\"principalId\":\"baiuebbaumny\",\"tenantId\":\"ped\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"location\":\"bckhsmtxpsi\",\"tags\":{\"rdqmhjjdhtldwkyz\":\"fhvpesaps\",\"cwsvlxotog\":\"uutkncw\",\"o\":\"wrupqsxvnmicykvc\",\"vnotyfjfcnj\":\"eil\"},\"id\":\"k\",\"name\":\"nxdhbt\",\"type\":\"kphywpnvjto\"}],\"nextLink\":\"ermclfplphoxuscr\"}")
                .toObject(IotHubDescriptionListResult.class);
        Assertions.assertEquals("bckhsmtxpsi", model.value().get(0).location());
        Assertions.assertEquals("fhvpesaps", model.value().get(0).tags().get("rdqmhjjdhtldwkyz"));
        Assertions.assertEquals("gnxytxhpzxbz", model.value().get(0).etag());
        Assertions.assertEquals(false, model.value().get(0).properties().disableLocalAuth());
        Assertions.assertEquals(true, model.value().get(0).properties().disableDeviceSas());
        Assertions.assertEquals(true, model.value().get(0).properties().disableModuleSas());
        Assertions.assertEquals(true, model.value().get(0).properties().restrictOutboundNetworkAccess());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).properties().publicNetworkAccess());
        Assertions.assertEquals("iklbbovpl", model.value().get(0).properties().minTlsVersion());
        Assertions.assertEquals(false, model.value().get(0).properties().enableFileUploadNotifications());
        Assertions.assertEquals("kde", model.value().get(0).properties().comments());
        Assertions.assertEquals(Capabilities.DEVICE_MANAGEMENT, model.value().get(0).properties().features());
        Assertions.assertEquals(true, model.value().get(0).properties().enableDataResidency());
        Assertions.assertEquals(IpVersion.IPV4IPV6, model.value().get(0).properties().ipVersion());
        Assertions.assertEquals(IotHubSku.S3, model.value().get(0).sku().name());
        Assertions.assertEquals(8474633220472193573L, model.value().get(0).sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IotHubDescriptionListResult model =
            new IotHubDescriptionListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IotHubDescriptionInner()
                                .withLocation("bckhsmtxpsi")
                                .withTags(
                                    mapOf(
                                        "rdqmhjjdhtldwkyz",
                                        "fhvpesaps",
                                        "cwsvlxotog",
                                        "uutkncw",
                                        "o",
                                        "wrupqsxvnmicykvc",
                                        "vnotyfjfcnj",
                                        "eil"))
                                .withEtag("gnxytxhpzxbz")
                                .withProperties(
                                    new IotHubProperties()
                                        .withAuthorizationPolicies(Arrays.asList())
                                        .withDisableLocalAuth(false)
                                        .withDisableDeviceSas(true)
                                        .withDisableModuleSas(true)
                                        .withRestrictOutboundNetworkAccess(true)
                                        .withAllowedFqdnList(Arrays.asList())
                                        .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                        .withIpFilterRules(Arrays.asList())
                                        .withMinTlsVersion("iklbbovpl")
                                        .withPrivateEndpointConnections(Arrays.asList())
                                        .withEventHubEndpoints(mapOf())
                                        .withStorageEndpoints(mapOf())
                                        .withMessagingEndpoints(mapOf())
                                        .withEnableFileUploadNotifications(false)
                                        .withComments("kde")
                                        .withFeatures(Capabilities.DEVICE_MANAGEMENT)
                                        .withEnableDataResidency(true)
                                        .withIpVersion(IpVersion.IPV4IPV6))
                                .withSku(new IotHubSkuInfo().withName(IotHubSku.S3).withCapacity(8474633220472193573L))
                                .withIdentity(
                                    new ArmIdentity()
                                        .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))));
        model = BinaryData.fromObject(model).toObject(IotHubDescriptionListResult.class);
        Assertions.assertEquals("bckhsmtxpsi", model.value().get(0).location());
        Assertions.assertEquals("fhvpesaps", model.value().get(0).tags().get("rdqmhjjdhtldwkyz"));
        Assertions.assertEquals("gnxytxhpzxbz", model.value().get(0).etag());
        Assertions.assertEquals(false, model.value().get(0).properties().disableLocalAuth());
        Assertions.assertEquals(true, model.value().get(0).properties().disableDeviceSas());
        Assertions.assertEquals(true, model.value().get(0).properties().disableModuleSas());
        Assertions.assertEquals(true, model.value().get(0).properties().restrictOutboundNetworkAccess());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).properties().publicNetworkAccess());
        Assertions.assertEquals("iklbbovpl", model.value().get(0).properties().minTlsVersion());
        Assertions.assertEquals(false, model.value().get(0).properties().enableFileUploadNotifications());
        Assertions.assertEquals("kde", model.value().get(0).properties().comments());
        Assertions.assertEquals(Capabilities.DEVICE_MANAGEMENT, model.value().get(0).properties().features());
        Assertions.assertEquals(true, model.value().get(0).properties().enableDataResidency());
        Assertions.assertEquals(IpVersion.IPV4IPV6, model.value().get(0).properties().ipVersion());
        Assertions.assertEquals(IotHubSku.S3, model.value().get(0).sku().name());
        Assertions.assertEquals(8474633220472193573L, model.value().get(0).sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
    }

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