// 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.models.EnvironmentCreateOrUpdateParameters;
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 EnvironmentCreateOrUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EnvironmentCreateOrUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"kind\":\"EnvironmentCreateOrUpdateParameters\",\"sku\":{\"name\":\"L1\",\"capacity\":900623903},\"location\":\"lniwpwcukjfkgiaw\",\"tags\":{\"dhsgcba\":\"ryplwckbasyypn\",\"dlikwyqkgfgibma\":\"phejkotynqgoulz\",\"yb\":\"gakeqsr\",\"lmmnkzsmodmglo\":\"qqedqytbciqfou\"}}")
                .toObject(EnvironmentCreateOrUpdateParameters.class);
        Assertions.assertEquals("lniwpwcukjfkgiaw", model.location());
        Assertions.assertEquals("ryplwckbasyypn", model.tags().get("dhsgcba"));
        Assertions.assertEquals(SkuName.L1, model.sku().name());
        Assertions.assertEquals(900623903, model.sku().capacity());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EnvironmentCreateOrUpdateParameters model =
            new EnvironmentCreateOrUpdateParameters()
                .withLocation("lniwpwcukjfkgiaw")
                .withTags(
                    mapOf(
                        "dhsgcba",
                        "ryplwckbasyypn",
                        "dlikwyqkgfgibma",
                        "phejkotynqgoulz",
                        "yb",
                        "gakeqsr",
                        "lmmnkzsmodmglo",
                        "qqedqytbciqfou"))
                .withSku(new Sku().withName(SkuName.L1).withCapacity(900623903));
        model = BinaryData.fromObject(model).toObject(EnvironmentCreateOrUpdateParameters.class);
        Assertions.assertEquals("lniwpwcukjfkgiaw", model.location());
        Assertions.assertEquals("ryplwckbasyypn", model.tags().get("dhsgcba"));
        Assertions.assertEquals(SkuName.L1, model.sku().name());
        Assertions.assertEquals(900623903, 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;
    }
}
