// 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.fluent.models.ApplicationInner;
import com.azure.resourcemanager.hdinsight.models.ApplicationListResult;
import com.azure.resourcemanager.hdinsight.models.ApplicationProperties;
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 ApplicationListResultTests {
    @Test
    public void testDeserialize() {
        ApplicationListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"etag\":\"mzlfmisgwb\",\"tags\":{\"dawkzbali\":\"e\",\"hashsfwxosow\":\"urqhaka\",\"cjooxdjebwpucwwf\":\"xcug\",\"hzceuojgjrwjue\":\"ovbvmeueciv\"},\"properties\":{\"installScriptActions\":[],\"uninstallScriptActions\":[],\"httpsEndpoints\":[],\"sshEndpoints\":[],\"provisioningState\":\"tdx\",\"applicationType\":\"txnrjaw\",\"applicationState\":\"wgxhn\",\"errors\":[],\"createdDate\":\"x\",\"marketplaceIdentifier\":\"kpycgklwndnhjd\",\"privateLinkConfigurations\":[]},\"id\":\"hvylwzbt\",\"name\":\"h\",\"type\":\"ujznb\"}],\"nextLink\":\"ow\"}")
                .toObject(ApplicationListResult.class);
        Assertions.assertEquals("mzlfmisgwb", model.value().get(0).etag());
        Assertions.assertEquals("e", model.value().get(0).tags().get("dawkzbali"));
        Assertions.assertEquals("txnrjaw", model.value().get(0).properties().applicationType());
    }

    @Test
    public void testSerialize() {
        ApplicationListResult model =
            new ApplicationListResult()
                .withValue(
                    Arrays
                        .asList(
                            new ApplicationInner()
                                .withEtag("mzlfmisgwb")
                                .withTags(
                                    mapOf(
                                        "dawkzbali",
                                        "e",
                                        "hashsfwxosow",
                                        "urqhaka",
                                        "cjooxdjebwpucwwf",
                                        "xcug",
                                        "hzceuojgjrwjue",
                                        "ovbvmeueciv"))
                                .withProperties(
                                    new ApplicationProperties()
                                        .withInstallScriptActions(Arrays.asList())
                                        .withUninstallScriptActions(Arrays.asList())
                                        .withHttpsEndpoints(Arrays.asList())
                                        .withSshEndpoints(Arrays.asList())
                                        .withApplicationType("txnrjaw")
                                        .withErrors(Arrays.asList())
                                        .withPrivateLinkConfigurations(Arrays.asList()))));
        model = BinaryData.fromObject(model).toObject(ApplicationListResult.class);
        Assertions.assertEquals("mzlfmisgwb", model.value().get(0).etag());
        Assertions.assertEquals("e", model.value().get(0).tags().get("dawkzbali"));
        Assertions.assertEquals("txnrjaw", model.value().get(0).properties().applicationType());
    }

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