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

package com.azure.resourcemanager.timeseriesinsights.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.timeseriesinsights.fluent.models.EnvironmentResourceInner;
import com.azure.resourcemanager.timeseriesinsights.models.Sku;
import com.azure.resourcemanager.timeseriesinsights.models.SkuName;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class EnvironmentResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EnvironmentResourceInner model =
            BinaryData
                .fromString(
                    "{\"kind\":\"EnvironmentResource\",\"sku\":{\"name\":\"P1\",\"capacity\":1218908818},\"location\":\"umkdosvqwhbmd\",\"tags\":{\"ppbhtqqrolfp\":\"jfddgmbmbe\"},\"id\":\"psalgbqux\",\"name\":\"gjyjgzjaoyfhrtxi\",\"type\":\"n\"}")
                .toObject(EnvironmentResourceInner.class);
        Assertions.assertEquals("umkdosvqwhbmd", model.location());
        Assertions.assertEquals("jfddgmbmbe", model.tags().get("ppbhtqqrolfp"));
        Assertions.assertEquals(SkuName.P1, model.sku().name());
        Assertions.assertEquals(1218908818, model.sku().capacity());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EnvironmentResourceInner model =
            new EnvironmentResourceInner()
                .withLocation("umkdosvqwhbmd")
                .withTags(mapOf("ppbhtqqrolfp", "jfddgmbmbe"))
                .withSku(new Sku().withName(SkuName.P1).withCapacity(1218908818));
        model = BinaryData.fromObject(model).toObject(EnvironmentResourceInner.class);
        Assertions.assertEquals("umkdosvqwhbmd", model.location());
        Assertions.assertEquals("jfddgmbmbe", model.tags().get("ppbhtqqrolfp"));
        Assertions.assertEquals(SkuName.P1, model.sku().name());
        Assertions.assertEquals(1218908818, model.sku().capacity());
    }

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