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

package com.azure.resourcemanager.dnsresolver.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dnsresolver.fluent.models.InboundEndpointInner;
import com.azure.resourcemanager.dnsresolver.models.IpAllocationMethod;
import com.azure.resourcemanager.dnsresolver.models.IpConfiguration;
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 InboundEndpointInnerTests {
    @Test
    public void testDeserialize() {
        InboundEndpointInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"zdxtayrlhmwhf\",\"properties\":{\"ipConfigurations\":[{\"privateIpAddress\":\"qobmtukk\",\"privateIpAllocationMethod\":\"Static\"},{\"privateIpAddress\":\"tihfx\",\"privateIpAllocationMethod\":\"Dynamic\"},{\"privateIpAddress\":\"pzvgnwzsymglzufc\",\"privateIpAllocationMethod\":\"Static\"}],\"provisioningState\":\"Failed\",\"resourceGuid\":\"bihanuf\"},\"location\":\"cbjy\",\"tags\":{\"xwczbyscnp\":\"ithxqhabifpi\"},\"id\":\"x\",\"name\":\"hiv\",\"type\":\"qniwbybrkxvdumj\"}")
                .toObject(InboundEndpointInner.class);
        Assertions.assertEquals("cbjy", model.location());
        Assertions.assertEquals("ithxqhabifpi", model.tags().get("xwczbyscnp"));
        Assertions.assertEquals("qobmtukk", model.ipConfigurations().get(0).privateIpAddress());
        Assertions.assertEquals(IpAllocationMethod.STATIC, model.ipConfigurations().get(0).privateIpAllocationMethod());
    }

    @Test
    public void testSerialize() {
        InboundEndpointInner model =
            new InboundEndpointInner()
                .withLocation("cbjy")
                .withTags(mapOf("xwczbyscnp", "ithxqhabifpi"))
                .withIpConfigurations(
                    Arrays
                        .asList(
                            new IpConfiguration()
                                .withPrivateIpAddress("qobmtukk")
                                .withPrivateIpAllocationMethod(IpAllocationMethod.STATIC),
                            new IpConfiguration()
                                .withPrivateIpAddress("tihfx")
                                .withPrivateIpAllocationMethod(IpAllocationMethod.DYNAMIC),
                            new IpConfiguration()
                                .withPrivateIpAddress("pzvgnwzsymglzufc")
                                .withPrivateIpAllocationMethod(IpAllocationMethod.STATIC)));
        model = BinaryData.fromObject(model).toObject(InboundEndpointInner.class);
        Assertions.assertEquals("cbjy", model.location());
        Assertions.assertEquals("ithxqhabifpi", model.tags().get("xwczbyscnp"));
        Assertions.assertEquals("qobmtukk", model.ipConfigurations().get(0).privateIpAddress());
        Assertions.assertEquals(IpAllocationMethod.STATIC, model.ipConfigurations().get(0).privateIpAllocationMethod());
    }

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