// 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.management.SubResource;
import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dnsresolver.fluent.models.VirtualNetworkLinkInner;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class VirtualNetworkLinkInnerTests {
    @Test
    public void testDeserialize() {
        VirtualNetworkLinkInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"okacspk\",\"properties\":{\"virtualNetwork\":{\"id\":\"hzdobpxjmflbvvnc\"},\"metadata\":{\"zjuqkhrsaj\":\"cciw\",\"mjmvxieduugidyjr\":\"wkuofoskghsauu\",\"y\":\"f\",\"hslkevleggzf\":\"osvexcsonpclhoc\"},\"provisioningState\":\"Failed\"},\"id\":\"mvfaxkffeiith\",\"name\":\"vmezy\",\"type\":\"shxmzsbbzoggigrx\"}")
                .toObject(VirtualNetworkLinkInner.class);
        Assertions.assertEquals("hzdobpxjmflbvvnc", model.virtualNetwork().id());
        Assertions.assertEquals("cciw", model.metadata().get("zjuqkhrsaj"));
    }

    @Test
    public void testSerialize() {
        VirtualNetworkLinkInner model =
            new VirtualNetworkLinkInner()
                .withVirtualNetwork(new SubResource().withId("hzdobpxjmflbvvnc"))
                .withMetadata(
                    mapOf(
                        "zjuqkhrsaj",
                        "cciw",
                        "mjmvxieduugidyjr",
                        "wkuofoskghsauu",
                        "y",
                        "f",
                        "hslkevleggzf",
                        "osvexcsonpclhoc"));
        model = BinaryData.fromObject(model).toObject(VirtualNetworkLinkInner.class);
        Assertions.assertEquals("hzdobpxjmflbvvnc", model.virtualNetwork().id());
        Assertions.assertEquals("cciw", model.metadata().get("zjuqkhrsaj"));
    }

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