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

package com.azure.resourcemanager.mobilenetwork.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mobilenetwork.fluent.models.AttachedDataNetworkInner;
import com.azure.resourcemanager.mobilenetwork.models.InterfaceProperties;
import com.azure.resourcemanager.mobilenetwork.models.NaptConfiguration;
import com.azure.resourcemanager.mobilenetwork.models.NaptEnabled;
import com.azure.resourcemanager.mobilenetwork.models.PinholeTimeouts;
import com.azure.resourcemanager.mobilenetwork.models.PortRange;
import com.azure.resourcemanager.mobilenetwork.models.PortReuseHoldTimes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AttachedDataNetworkInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AttachedDataNetworkInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Canceled\",\"userPlaneDataInterface\":{\"name\":\"quvgjxpybczme\",\"ipv4Address\":\"tzopbsphrupidgsy\",\"ipv4Subnet\":\"ejhphoyc\",\"ipv4Gateway\":\"xaobhdxbmtqioqjz\"},\"dnsAddresses\":[\"tbmufpo\",\"noi\"],\"naptConfiguration\":{\"enabled\":\"Disabled\",\"portRange\":{\"minPort\":167840319,\"maxPort\":201473614},\"portReuseHoldTime\":{\"tcp\":1372882397,\"udp\":1472149737},\"pinholeLimits\":231072361,\"pinholeTimeouts\":{\"tcp\":1450276464,\"udp\":1792128890,\"icmp\":1864680039}},\"userEquipmentAddressPoolPrefix\":[\"c\"],\"userEquipmentStaticAddressPoolPrefix\":[\"dznrbtcqq\",\"nq\",\"lhqgnufooojy\",\"ifsqesaagdfmg\"]},\"location\":\"lhjxr\",\"tags\":{\"uajpsquc\":\"wmrvktsizntocipa\"},\"id\":\"poyfdkfogkn\",\"name\":\"gjofjd\",\"type\":\"eqsrdeupewnwreit\"}")
                .toObject(AttachedDataNetworkInner.class);
        Assertions.assertEquals("lhjxr", model.location());
        Assertions.assertEquals("wmrvktsizntocipa", model.tags().get("uajpsquc"));
        Assertions.assertEquals("quvgjxpybczme", model.userPlaneDataInterface().name());
        Assertions.assertEquals("tzopbsphrupidgsy", model.userPlaneDataInterface().ipv4Address());
        Assertions.assertEquals("ejhphoyc", model.userPlaneDataInterface().ipv4Subnet());
        Assertions.assertEquals("xaobhdxbmtqioqjz", model.userPlaneDataInterface().ipv4Gateway());
        Assertions.assertEquals("tbmufpo", model.dnsAddresses().get(0));
        Assertions.assertEquals(NaptEnabled.DISABLED, model.naptConfiguration().enabled());
        Assertions.assertEquals(167840319, model.naptConfiguration().portRange().minPort());
        Assertions.assertEquals(201473614, model.naptConfiguration().portRange().maxPort());
        Assertions.assertEquals(1372882397, model.naptConfiguration().portReuseHoldTime().tcp());
        Assertions.assertEquals(1472149737, model.naptConfiguration().portReuseHoldTime().udp());
        Assertions.assertEquals(231072361, model.naptConfiguration().pinholeLimits());
        Assertions.assertEquals(1450276464, model.naptConfiguration().pinholeTimeouts().tcp());
        Assertions.assertEquals(1792128890, model.naptConfiguration().pinholeTimeouts().udp());
        Assertions.assertEquals(1864680039, model.naptConfiguration().pinholeTimeouts().icmp());
        Assertions.assertEquals("c", model.userEquipmentAddressPoolPrefix().get(0));
        Assertions.assertEquals("dznrbtcqq", model.userEquipmentStaticAddressPoolPrefix().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AttachedDataNetworkInner model =
            new AttachedDataNetworkInner()
                .withLocation("lhjxr")
                .withTags(mapOf("uajpsquc", "wmrvktsizntocipa"))
                .withUserPlaneDataInterface(
                    new InterfaceProperties()
                        .withName("quvgjxpybczme")
                        .withIpv4Address("tzopbsphrupidgsy")
                        .withIpv4Subnet("ejhphoyc")
                        .withIpv4Gateway("xaobhdxbmtqioqjz"))
                .withDnsAddresses(Arrays.asList("tbmufpo", "noi"))
                .withNaptConfiguration(
                    new NaptConfiguration()
                        .withEnabled(NaptEnabled.DISABLED)
                        .withPortRange(new PortRange().withMinPort(167840319).withMaxPort(201473614))
                        .withPortReuseHoldTime(new PortReuseHoldTimes().withTcp(1372882397).withUdp(1472149737))
                        .withPinholeLimits(231072361)
                        .withPinholeTimeouts(
                            new PinholeTimeouts().withTcp(1450276464).withUdp(1792128890).withIcmp(1864680039)))
                .withUserEquipmentAddressPoolPrefix(Arrays.asList("c"))
                .withUserEquipmentStaticAddressPoolPrefix(
                    Arrays.asList("dznrbtcqq", "nq", "lhqgnufooojy", "ifsqesaagdfmg"));
        model = BinaryData.fromObject(model).toObject(AttachedDataNetworkInner.class);
        Assertions.assertEquals("lhjxr", model.location());
        Assertions.assertEquals("wmrvktsizntocipa", model.tags().get("uajpsquc"));
        Assertions.assertEquals("quvgjxpybczme", model.userPlaneDataInterface().name());
        Assertions.assertEquals("tzopbsphrupidgsy", model.userPlaneDataInterface().ipv4Address());
        Assertions.assertEquals("ejhphoyc", model.userPlaneDataInterface().ipv4Subnet());
        Assertions.assertEquals("xaobhdxbmtqioqjz", model.userPlaneDataInterface().ipv4Gateway());
        Assertions.assertEquals("tbmufpo", model.dnsAddresses().get(0));
        Assertions.assertEquals(NaptEnabled.DISABLED, model.naptConfiguration().enabled());
        Assertions.assertEquals(167840319, model.naptConfiguration().portRange().minPort());
        Assertions.assertEquals(201473614, model.naptConfiguration().portRange().maxPort());
        Assertions.assertEquals(1372882397, model.naptConfiguration().portReuseHoldTime().tcp());
        Assertions.assertEquals(1472149737, model.naptConfiguration().portReuseHoldTime().udp());
        Assertions.assertEquals(231072361, model.naptConfiguration().pinholeLimits());
        Assertions.assertEquals(1450276464, model.naptConfiguration().pinholeTimeouts().tcp());
        Assertions.assertEquals(1792128890, model.naptConfiguration().pinholeTimeouts().udp());
        Assertions.assertEquals(1864680039, model.naptConfiguration().pinholeTimeouts().icmp());
        Assertions.assertEquals("c", model.userEquipmentAddressPoolPrefix().get(0));
        Assertions.assertEquals("dznrbtcqq", model.userEquipmentStaticAddressPoolPrefix().get(0));
    }

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