// 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.Gen2EnvironmentResource;
import com.azure.resourcemanager.timeseriesinsights.models.Gen2StorageConfigurationOutput;
import com.azure.resourcemanager.timeseriesinsights.models.PropertyType;
import com.azure.resourcemanager.timeseriesinsights.models.Sku;
import com.azure.resourcemanager.timeseriesinsights.models.SkuName;
import com.azure.resourcemanager.timeseriesinsights.models.TimeSeriesIdProperty;
import com.azure.resourcemanager.timeseriesinsights.models.WarmStoreConfigurationProperties;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class Gen2EnvironmentResourceTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        Gen2EnvironmentResource model =
            BinaryData
                .fromString(
                    "{\"kind\":\"Gen2\",\"properties\":{\"timeSeriesIdProperties\":[{\"name\":\"pxtt\",\"type\":\"String\"},{\"name\":\"bnlankxmyskpb\",\"type\":\"String\"}],\"storageConfiguration\":{\"accountName\":\"btkcxywnytnrsyn\"},\"warmStoreConfiguration\":{\"dataRetention\":\"PT96H34M54S\"},\"dataAccessId\":\"987697ad-7913-431f-901a-e1c10deeb0b0\",\"dataAccessFqdn\":\"by\",\"status\":{},\"provisioningState\":\"Updating\",\"creationTime\":\"2021-04-19T03:11:49Z\"},\"sku\":{\"name\":\"S2\",\"capacity\":384139525},\"location\":\"dbabp\",\"tags\":{\"yazttbtwwrqpue\":\"rqlfktsthsucocmn\",\"xibxujwbhqwalm\":\"ckzywbiexzfeyue\",\"ux\":\"zyoxaepdkzjan\",\"zt\":\"hdwbavxbniwdjs\"},\"id\":\"dbpgnxytxhp\",\"name\":\"xbzpfzab\",\"type\":\"lcuhxwtctyqiklb\"}")
                .toObject(Gen2EnvironmentResource.class);
        Assertions.assertEquals("dbabp", model.location());
        Assertions.assertEquals("rqlfktsthsucocmn", model.tags().get("yazttbtwwrqpue"));
        Assertions.assertEquals(SkuName.S2, model.sku().name());
        Assertions.assertEquals(384139525, model.sku().capacity());
        Assertions.assertEquals("pxtt", model.timeSeriesIdProperties().get(0).name());
        Assertions.assertEquals(PropertyType.STRING, model.timeSeriesIdProperties().get(0).type());
        Assertions.assertEquals("btkcxywnytnrsyn", model.storageConfiguration().accountName());
        Assertions.assertEquals(Duration.parse("PT96H34M54S"), model.warmStoreConfiguration().dataRetention());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        Gen2EnvironmentResource model =
            new Gen2EnvironmentResource()
                .withLocation("dbabp")
                .withTags(
                    mapOf(
                        "yazttbtwwrqpue",
                        "rqlfktsthsucocmn",
                        "xibxujwbhqwalm",
                        "ckzywbiexzfeyue",
                        "ux",
                        "zyoxaepdkzjan",
                        "zt",
                        "hdwbavxbniwdjs"))
                .withSku(new Sku().withName(SkuName.S2).withCapacity(384139525))
                .withTimeSeriesIdProperties(
                    Arrays
                        .asList(
                            new TimeSeriesIdProperty().withName("pxtt").withType(PropertyType.STRING),
                            new TimeSeriesIdProperty().withName("bnlankxmyskpb").withType(PropertyType.STRING)))
                .withStorageConfiguration(new Gen2StorageConfigurationOutput().withAccountName("btkcxywnytnrsyn"))
                .withWarmStoreConfiguration(
                    new WarmStoreConfigurationProperties().withDataRetention(Duration.parse("PT96H34M54S")));
        model = BinaryData.fromObject(model).toObject(Gen2EnvironmentResource.class);
        Assertions.assertEquals("dbabp", model.location());
        Assertions.assertEquals("rqlfktsthsucocmn", model.tags().get("yazttbtwwrqpue"));
        Assertions.assertEquals(SkuName.S2, model.sku().name());
        Assertions.assertEquals(384139525, model.sku().capacity());
        Assertions.assertEquals("pxtt", model.timeSeriesIdProperties().get(0).name());
        Assertions.assertEquals(PropertyType.STRING, model.timeSeriesIdProperties().get(0).type());
        Assertions.assertEquals("btkcxywnytnrsyn", model.storageConfiguration().accountName());
        Assertions.assertEquals(Duration.parse("PT96H34M54S"), model.warmStoreConfiguration().dataRetention());
    }

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