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

package com.azure.resourcemanager.servicenetworking.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicenetworking.models.AssociationSubnetUpdate;
import com.azure.resourcemanager.servicenetworking.models.AssociationType;
import com.azure.resourcemanager.servicenetworking.models.AssociationUpdate;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AssociationUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AssociationUpdate model =
            BinaryData
                .fromString(
                    "{\"tags\":{\"hwxmnteiwa\":\"sdkf\",\"fsrpymzidnse\":\"pvkmijcmmxdcuf\",\"yc\":\"cxtbzsg\",\"mdwzjeiachboo\":\"sne\"},\"properties\":{\"associationType\":\"subnets\",\"subnet\":{\"id\":\"sfqpteehz\"}}}")
                .toObject(AssociationUpdate.class);
        Assertions.assertEquals("sdkf", model.tags().get("hwxmnteiwa"));
        Assertions.assertEquals(AssociationType.SUBNETS, model.associationType());
        Assertions.assertEquals("sfqpteehz", model.subnet().id());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AssociationUpdate model =
            new AssociationUpdate()
                .withTags(
                    mapOf(
                        "hwxmnteiwa",
                        "sdkf",
                        "fsrpymzidnse",
                        "pvkmijcmmxdcuf",
                        "yc",
                        "cxtbzsg",
                        "mdwzjeiachboo",
                        "sne"))
                .withAssociationType(AssociationType.SUBNETS)
                .withSubnet(new AssociationSubnetUpdate().withId("sfqpteehz"));
        model = BinaryData.fromObject(model).toObject(AssociationUpdate.class);
        Assertions.assertEquals("sdkf", model.tags().get("hwxmnteiwa"));
        Assertions.assertEquals(AssociationType.SUBNETS, model.associationType());
        Assertions.assertEquals("sfqpteehz", model.subnet().id());
    }

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