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

public final class EnvironmentVersionPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EnvironmentVersionProperties model =
            BinaryData
                .fromString(
                    "{\"autoRebuild\":\"OnBaseImageUpdate\",\"build\":{\"contextUri\":\"hjxa\",\"dockerfilePath\":\"vjgsl\"},\"condaFile\":\"dilmyww\",\"environmentType\":\"UserCreated\",\"image\":\"xnyed\",\"inferenceConfig\":{\"livenessRoute\":{\"path\":\"yvudtjuewbci\",\"port\":1871891438},\"readinessRoute\":{\"path\":\"uwhcjyxccybv\",\"port\":436827826},\"scoringRoute\":{\"path\":\"akkud\",\"port\":417091375}},\"osType\":\"Linux\",\"isAnonymous\":true,\"isArchived\":false,\"description\":\"agst\",\"properties\":{\"gsj\":\"hpfkyrkdbdgi\",\"obaiyhddviaceg\":\"mnwqj\",\"ntfpmvmemfnc\":\"n\",\"xlllchp\":\"dwvvba\"},\"tags\":{\"jcswsmys\":\"zevwrdnhfukuv\",\"lerchpq\":\"uluqypfc\"}}")
                .toObject(EnvironmentVersionProperties.class);
        Assertions.assertEquals("agst", model.description());
        Assertions.assertEquals("hpfkyrkdbdgi", model.properties().get("gsj"));
        Assertions.assertEquals("zevwrdnhfukuv", model.tags().get("jcswsmys"));
        Assertions.assertEquals(true, model.isAnonymous());
        Assertions.assertEquals(false, model.isArchived());
        Assertions.assertEquals(AutoRebuildSetting.ON_BASE_IMAGE_UPDATE, model.autoRebuild());
        Assertions.assertEquals("hjxa", model.build().contextUri());
        Assertions.assertEquals("vjgsl", model.build().dockerfilePath());
        Assertions.assertEquals("dilmyww", model.condaFile());
        Assertions.assertEquals("xnyed", model.image());
        Assertions.assertEquals("yvudtjuewbci", model.inferenceConfig().livenessRoute().path());
        Assertions.assertEquals(1871891438, model.inferenceConfig().livenessRoute().port());
        Assertions.assertEquals("uwhcjyxccybv", model.inferenceConfig().readinessRoute().path());
        Assertions.assertEquals(436827826, model.inferenceConfig().readinessRoute().port());
        Assertions.assertEquals("akkud", model.inferenceConfig().scoringRoute().path());
        Assertions.assertEquals(417091375, model.inferenceConfig().scoringRoute().port());
        Assertions.assertEquals(OperatingSystemType.LINUX, model.osType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EnvironmentVersionProperties model =
            new EnvironmentVersionProperties()
                .withDescription("agst")
                .withProperties(
                    mapOf("gsj", "hpfkyrkdbdgi", "obaiyhddviaceg", "mnwqj", "ntfpmvmemfnc", "n", "xlllchp", "dwvvba"))
                .withTags(mapOf("jcswsmys", "zevwrdnhfukuv", "lerchpq", "uluqypfc"))
                .withIsAnonymous(true)
                .withIsArchived(false)
                .withAutoRebuild(AutoRebuildSetting.ON_BASE_IMAGE_UPDATE)
                .withBuild(new BuildContext().withContextUri("hjxa").withDockerfilePath("vjgsl"))
                .withCondaFile("dilmyww")
                .withImage("xnyed")
                .withInferenceConfig(
                    new InferenceContainerProperties()
                        .withLivenessRoute(new Route().withPath("yvudtjuewbci").withPort(1871891438))
                        .withReadinessRoute(new Route().withPath("uwhcjyxccybv").withPort(436827826))
                        .withScoringRoute(new Route().withPath("akkud").withPort(417091375)))
                .withOsType(OperatingSystemType.LINUX);
        model = BinaryData.fromObject(model).toObject(EnvironmentVersionProperties.class);
        Assertions.assertEquals("agst", model.description());
        Assertions.assertEquals("hpfkyrkdbdgi", model.properties().get("gsj"));
        Assertions.assertEquals("zevwrdnhfukuv", model.tags().get("jcswsmys"));
        Assertions.assertEquals(true, model.isAnonymous());
        Assertions.assertEquals(false, model.isArchived());
        Assertions.assertEquals(AutoRebuildSetting.ON_BASE_IMAGE_UPDATE, model.autoRebuild());
        Assertions.assertEquals("hjxa", model.build().contextUri());
        Assertions.assertEquals("vjgsl", model.build().dockerfilePath());
        Assertions.assertEquals("dilmyww", model.condaFile());
        Assertions.assertEquals("xnyed", model.image());
        Assertions.assertEquals("yvudtjuewbci", model.inferenceConfig().livenessRoute().path());
        Assertions.assertEquals(1871891438, model.inferenceConfig().livenessRoute().port());
        Assertions.assertEquals("uwhcjyxccybv", model.inferenceConfig().readinessRoute().path());
        Assertions.assertEquals(436827826, model.inferenceConfig().readinessRoute().port());
        Assertions.assertEquals("akkud", model.inferenceConfig().scoringRoute().path());
        Assertions.assertEquals(417091375, model.inferenceConfig().scoringRoute().port());
        Assertions.assertEquals(OperatingSystemType.LINUX, model.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;
    }
}
