// 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.Gen1EnvironmentUpdateParameters;
import com.azure.resourcemanager.timeseriesinsights.models.Sku;
import com.azure.resourcemanager.timeseriesinsights.models.SkuName;
import com.azure.resourcemanager.timeseriesinsights.models.StorageLimitExceededBehavior;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class Gen1EnvironmentUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        Gen1EnvironmentUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"kind\":\"Gen1\",\"sku\":{\"name\":\"L1\",\"capacity\":891942589},\"properties\":{\"dataRetentionTime\":\"PT50H33M14S\",\"storageLimitExceededBehavior\":\"PurgeOldData\"},\"tags\":{\"vjektcxsenh\":\"beypewrmjmw\",\"rzpwvlqdqgbiq\":\"lrsf\"}}")
                .toObject(Gen1EnvironmentUpdateParameters.class);
        Assertions.assertEquals("beypewrmjmw", model.tags().get("vjektcxsenh"));
        Assertions.assertEquals(SkuName.L1, model.sku().name());
        Assertions.assertEquals(891942589, model.sku().capacity());
        Assertions.assertEquals(Duration.parse("PT50H33M14S"), model.dataRetentionTime());
        Assertions.assertEquals(StorageLimitExceededBehavior.PURGE_OLD_DATA, model.storageLimitExceededBehavior());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        Gen1EnvironmentUpdateParameters model =
            new Gen1EnvironmentUpdateParameters()
                .withTags(mapOf("vjektcxsenh", "beypewrmjmw", "rzpwvlqdqgbiq", "lrsf"))
                .withSku(new Sku().withName(SkuName.L1).withCapacity(891942589))
                .withDataRetentionTime(Duration.parse("PT50H33M14S"))
                .withStorageLimitExceededBehavior(StorageLimitExceededBehavior.PURGE_OLD_DATA);
        model = BinaryData.fromObject(model).toObject(Gen1EnvironmentUpdateParameters.class);
        Assertions.assertEquals("beypewrmjmw", model.tags().get("vjektcxsenh"));
        Assertions.assertEquals(SkuName.L1, model.sku().name());
        Assertions.assertEquals(891942589, model.sku().capacity());
        Assertions.assertEquals(Duration.parse("PT50H33M14S"), model.dataRetentionTime());
        Assertions.assertEquals(StorageLimitExceededBehavior.PURGE_OLD_DATA, model.storageLimitExceededBehavior());
    }

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