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

package com.azure.resourcemanager.machinelearning.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.machinelearning.fluent.models.ComponentVersionInner;
import com.azure.resourcemanager.machinelearning.models.ComponentVersionProperties;
import com.azure.resourcemanager.machinelearning.models.ComponentVersionResourceArmPaginatedResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ComponentVersionResourceArmPaginatedResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ComponentVersionResourceArmPaginatedResult model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"sxkm\",\"value\":[{\"properties\":{\"componentSpec\":\"datakrrjrea\",\"isAnonymous\":false,\"isArchived\":true,\"description\":\"mhjglikkxwslolb\",\"properties\":{},\"tags\":{}},\"id\":\"zlmvfelfktgp\",\"name\":\"crpw\",\"type\":\"xeznoi\"}]}")
                .toObject(ComponentVersionResourceArmPaginatedResult.class);
        Assertions.assertEquals("sxkm", model.nextLink());
        Assertions.assertEquals("mhjglikkxwslolb", model.value().get(0).properties().description());
        Assertions.assertEquals(false, model.value().get(0).properties().isAnonymous());
        Assertions.assertEquals(true, model.value().get(0).properties().isArchived());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ComponentVersionResourceArmPaginatedResult model =
            new ComponentVersionResourceArmPaginatedResult()
                .withNextLink("sxkm")
                .withValue(
                    Arrays
                        .asList(
                            new ComponentVersionInner()
                                .withProperties(
                                    new ComponentVersionProperties()
                                        .withDescription("mhjglikkxwslolb")
                                        .withProperties(mapOf())
                                        .withTags(mapOf())
                                        .withIsAnonymous(false)
                                        .withIsArchived(true)
                                        .withComponentSpec("datakrrjrea"))));
        model = BinaryData.fromObject(model).toObject(ComponentVersionResourceArmPaginatedResult.class);
        Assertions.assertEquals("sxkm", model.nextLink());
        Assertions.assertEquals("mhjglikkxwslolb", model.value().get(0).properties().description());
        Assertions.assertEquals(false, model.value().get(0).properties().isAnonymous());
        Assertions.assertEquals(true, model.value().get(0).properties().isArchived());
    }

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