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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.VirtualNetworkInner;
import com.azure.resourcemanager.devtestlabs.models.Subnet;
import com.azure.resourcemanager.devtestlabs.models.SubnetOverride;
import com.azure.resourcemanager.devtestlabs.models.UsagePermissionType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class VirtualNetworkInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        VirtualNetworkInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"allowedSubnets\":[{\"resourceId\":\"i\",\"labSubnetName\":\"gvelfc\",\"allowPublicIp\":\"Deny\"}],\"description\":\"cb\",\"externalProviderResourceId\":\"ds\",\"externalSubnets\":[{\"id\":\"o\",\"name\":\"egstmninwjizci\"},{\"id\":\"ghgshejjtbxqmu\",\"name\":\"xlxqzvn\"}],\"subnetOverrides\":[{\"resourceId\":\"ycucrwnamikzeb\",\"labSubnetName\":\"bsmswziqgf\",\"useInVmCreationPermission\":\"Allow\",\"usePublicIpAddressPermission\":\"Allow\",\"virtualNetworkPoolName\":\"swhvhczznvfbycj\"},{\"resourceId\":\"jww\",\"labSubnetName\":\"z\",\"useInVmCreationPermission\":\"Allow\",\"usePublicIpAddressPermission\":\"Default\",\"virtualNetworkPoolName\":\"hndvnoamldsehao\"},{\"resourceId\":\"jhhflzokxcoxpel\",\"labSubnetName\":\"eta\",\"useInVmCreationPermission\":\"Default\",\"usePublicIpAddressPermission\":\"Default\",\"virtualNetworkPoolName\":\"tft\"},{\"resourceId\":\"pnpbswveflocc\",\"labSubnetName\":\"mozi\",\"useInVmCreationPermission\":\"Default\",\"usePublicIpAddressPermission\":\"Deny\",\"virtualNetworkPoolName\":\"txx\"}],\"createdDate\":\"2021-06-29T13:46:46Z\",\"provisioningState\":\"cxcjxgry\",\"uniqueIdentifier\":\"mpcycilrmcaykgg\"},\"location\":\"oxuztrksx\",\"tags\":{\"cpfnznthjtwkja\":\"d\",\"tcqiosmg\":\"srxuzvoam\"},\"id\":\"zah\",\"name\":\"xqdlyrtltlapr\",\"type\":\"tz\"}")
                .toObject(VirtualNetworkInner.class);
        Assertions.assertEquals("oxuztrksx", model.location());
        Assertions.assertEquals("d", model.tags().get("cpfnznthjtwkja"));
        Assertions.assertEquals("i", model.allowedSubnets().get(0).resourceId());
        Assertions.assertEquals("gvelfc", model.allowedSubnets().get(0).labSubnetName());
        Assertions.assertEquals(UsagePermissionType.DENY, model.allowedSubnets().get(0).allowPublicIp());
        Assertions.assertEquals("cb", model.description());
        Assertions.assertEquals("ds", model.externalProviderResourceId());
        Assertions.assertEquals("ycucrwnamikzeb", model.subnetOverrides().get(0).resourceId());
        Assertions.assertEquals("bsmswziqgf", model.subnetOverrides().get(0).labSubnetName());
        Assertions.assertEquals(UsagePermissionType.ALLOW, model.subnetOverrides().get(0).useInVmCreationPermission());
        Assertions
            .assertEquals(UsagePermissionType.ALLOW, model.subnetOverrides().get(0).usePublicIpAddressPermission());
        Assertions.assertEquals("swhvhczznvfbycj", model.subnetOverrides().get(0).virtualNetworkPoolName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        VirtualNetworkInner model =
            new VirtualNetworkInner()
                .withLocation("oxuztrksx")
                .withTags(mapOf("cpfnznthjtwkja", "d", "tcqiosmg", "srxuzvoam"))
                .withAllowedSubnets(
                    Arrays
                        .asList(
                            new Subnet()
                                .withResourceId("i")
                                .withLabSubnetName("gvelfc")
                                .withAllowPublicIp(UsagePermissionType.DENY)))
                .withDescription("cb")
                .withExternalProviderResourceId("ds")
                .withSubnetOverrides(
                    Arrays
                        .asList(
                            new SubnetOverride()
                                .withResourceId("ycucrwnamikzeb")
                                .withLabSubnetName("bsmswziqgf")
                                .withUseInVmCreationPermission(UsagePermissionType.ALLOW)
                                .withUsePublicIpAddressPermission(UsagePermissionType.ALLOW)
                                .withVirtualNetworkPoolName("swhvhczznvfbycj"),
                            new SubnetOverride()
                                .withResourceId("jww")
                                .withLabSubnetName("z")
                                .withUseInVmCreationPermission(UsagePermissionType.ALLOW)
                                .withUsePublicIpAddressPermission(UsagePermissionType.DEFAULT)
                                .withVirtualNetworkPoolName("hndvnoamldsehao"),
                            new SubnetOverride()
                                .withResourceId("jhhflzokxcoxpel")
                                .withLabSubnetName("eta")
                                .withUseInVmCreationPermission(UsagePermissionType.DEFAULT)
                                .withUsePublicIpAddressPermission(UsagePermissionType.DEFAULT)
                                .withVirtualNetworkPoolName("tft"),
                            new SubnetOverride()
                                .withResourceId("pnpbswveflocc")
                                .withLabSubnetName("mozi")
                                .withUseInVmCreationPermission(UsagePermissionType.DEFAULT)
                                .withUsePublicIpAddressPermission(UsagePermissionType.DENY)
                                .withVirtualNetworkPoolName("txx")));
        model = BinaryData.fromObject(model).toObject(VirtualNetworkInner.class);
        Assertions.assertEquals("oxuztrksx", model.location());
        Assertions.assertEquals("d", model.tags().get("cpfnznthjtwkja"));
        Assertions.assertEquals("i", model.allowedSubnets().get(0).resourceId());
        Assertions.assertEquals("gvelfc", model.allowedSubnets().get(0).labSubnetName());
        Assertions.assertEquals(UsagePermissionType.DENY, model.allowedSubnets().get(0).allowPublicIp());
        Assertions.assertEquals("cb", model.description());
        Assertions.assertEquals("ds", model.externalProviderResourceId());
        Assertions.assertEquals("ycucrwnamikzeb", model.subnetOverrides().get(0).resourceId());
        Assertions.assertEquals("bsmswziqgf", model.subnetOverrides().get(0).labSubnetName());
        Assertions.assertEquals(UsagePermissionType.ALLOW, model.subnetOverrides().get(0).useInVmCreationPermission());
        Assertions
            .assertEquals(UsagePermissionType.ALLOW, model.subnetOverrides().get(0).usePublicIpAddressPermission());
        Assertions.assertEquals("swhvhczznvfbycj", model.subnetOverrides().get(0).virtualNetworkPoolName());
    }

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