// 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.EnvironmentVersionInner;
import com.azure.resourcemanager.machinelearning.models.AutoRebuildSetting;
import com.azure.resourcemanager.machinelearning.models.EnvironmentVersionProperties;
import com.azure.resourcemanager.machinelearning.models.EnvironmentVersionResourceArmPaginatedResult;
import com.azure.resourcemanager.machinelearning.models.OperatingSystemType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class EnvironmentVersionResourceArmPaginatedResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EnvironmentVersionResourceArmPaginatedResult model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"cimpevfg\",\"value\":[{\"properties\":{\"autoRebuild\":\"Disabled\",\"condaFile\":\"bywdxsmicc\",\"environmentType\":\"Curated\",\"image\":\"scjfnyns\",\"osType\":\"Windows\",\"isAnonymous\":true,\"isArchived\":false,\"description\":\"qytibyowbblgyavu\",\"properties\":{},\"tags\":{}},\"id\":\"joxoism\",\"name\":\"ksbpimlqoljx\",\"type\":\"cgxxlxs\"}]}")
                .toObject(EnvironmentVersionResourceArmPaginatedResult.class);
        Assertions.assertEquals("cimpevfg", model.nextLink());
        Assertions.assertEquals("qytibyowbblgyavu", model.value().get(0).properties().description());
        Assertions.assertEquals(true, model.value().get(0).properties().isAnonymous());
        Assertions.assertEquals(false, model.value().get(0).properties().isArchived());
        Assertions.assertEquals(AutoRebuildSetting.DISABLED, model.value().get(0).properties().autoRebuild());
        Assertions.assertEquals("bywdxsmicc", model.value().get(0).properties().condaFile());
        Assertions.assertEquals("scjfnyns", model.value().get(0).properties().image());
        Assertions.assertEquals(OperatingSystemType.WINDOWS, model.value().get(0).properties().osType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EnvironmentVersionResourceArmPaginatedResult model =
            new EnvironmentVersionResourceArmPaginatedResult()
                .withNextLink("cimpevfg")
                .withValue(
                    Arrays
                        .asList(
                            new EnvironmentVersionInner()
                                .withProperties(
                                    new EnvironmentVersionProperties()
                                        .withDescription("qytibyowbblgyavu")
                                        .withProperties(mapOf())
                                        .withTags(mapOf())
                                        .withIsAnonymous(true)
                                        .withIsArchived(false)
                                        .withAutoRebuild(AutoRebuildSetting.DISABLED)
                                        .withCondaFile("bywdxsmicc")
                                        .withImage("scjfnyns")
                                        .withOsType(OperatingSystemType.WINDOWS))));
        model = BinaryData.fromObject(model).toObject(EnvironmentVersionResourceArmPaginatedResult.class);
        Assertions.assertEquals("cimpevfg", model.nextLink());
        Assertions.assertEquals("qytibyowbblgyavu", model.value().get(0).properties().description());
        Assertions.assertEquals(true, model.value().get(0).properties().isAnonymous());
        Assertions.assertEquals(false, model.value().get(0).properties().isArchived());
        Assertions.assertEquals(AutoRebuildSetting.DISABLED, model.value().get(0).properties().autoRebuild());
        Assertions.assertEquals("bywdxsmicc", model.value().get(0).properties().condaFile());
        Assertions.assertEquals("scjfnyns", model.value().get(0).properties().image());
        Assertions.assertEquals(OperatingSystemType.WINDOWS, model.value().get(0).properties().osType());
    }

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