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

package com.azure.resourcemanager.hdinsight.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.hdinsight.models.VersionSpec;
import com.azure.resourcemanager.hdinsight.models.VersionsCapability;
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 VersionsCapabilityTests {
    @Test
    public void testDeserialize() {
        VersionsCapability model =
            BinaryData
                .fromString(
                    "{\"available\":[{\"friendlyName\":\"ntorzihleosjswsr\",\"displayName\":\"lyzrpzbchckqqzqi\",\"isDefault\":false,\"componentVersions\":{\"yatrwy\":\"uiizynke\",\"ibzyhwitsmyp\":\"q\",\"biknsorgjhxbld\":\"ynpcdpumnzgmwznm\",\"dmtnc\":\"lwwrl\"}},{\"friendlyName\":\"kotl\",\"displayName\":\"d\",\"isDefault\":false,\"componentVersions\":{\"tdtbnnhadooc\":\"ocogj\"}},{\"friendlyName\":\"vcikhnvpamqgx\",\"displayName\":\"u\",\"isDefault\":false,\"componentVersions\":{\"elwuipi\":\"wggxkallat\",\"rhyrnxxmueed\":\"cjzkzivgvvcna\"}}]}")
                .toObject(VersionsCapability.class);
        Assertions.assertEquals("ntorzihleosjswsr", model.available().get(0).friendlyName());
        Assertions.assertEquals("lyzrpzbchckqqzqi", model.available().get(0).displayName());
        Assertions.assertEquals(false, model.available().get(0).isDefault());
        Assertions.assertEquals("uiizynke", model.available().get(0).componentVersions().get("yatrwy"));
    }

    @Test
    public void testSerialize() {
        VersionsCapability model =
            new VersionsCapability()
                .withAvailable(
                    Arrays
                        .asList(
                            new VersionSpec()
                                .withFriendlyName("ntorzihleosjswsr")
                                .withDisplayName("lyzrpzbchckqqzqi")
                                .withIsDefault(false)
                                .withComponentVersions(
                                    mapOf(
                                        "yatrwy",
                                        "uiizynke",
                                        "ibzyhwitsmyp",
                                        "q",
                                        "biknsorgjhxbld",
                                        "ynpcdpumnzgmwznm",
                                        "dmtnc",
                                        "lwwrl")),
                            new VersionSpec()
                                .withFriendlyName("kotl")
                                .withDisplayName("d")
                                .withIsDefault(false)
                                .withComponentVersions(mapOf("tdtbnnhadooc", "ocogj")),
                            new VersionSpec()
                                .withFriendlyName("vcikhnvpamqgx")
                                .withDisplayName("u")
                                .withIsDefault(false)
                                .withComponentVersions(
                                    mapOf("elwuipi", "wggxkallat", "rhyrnxxmueed", "cjzkzivgvvcna"))));
        model = BinaryData.fromObject(model).toObject(VersionsCapability.class);
        Assertions.assertEquals("ntorzihleosjswsr", model.available().get(0).friendlyName());
        Assertions.assertEquals("lyzrpzbchckqqzqi", model.available().get(0).displayName());
        Assertions.assertEquals(false, model.available().get(0).isDefault());
        Assertions.assertEquals("uiizynke", model.available().get(0).componentVersions().get("yatrwy"));
    }

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