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

package com.azure.resourcemanager.frontdoor.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.frontdoor.fluent.models.TimeseriesInner;
import com.azure.resourcemanager.frontdoor.models.AggregationInterval;
import com.azure.resourcemanager.frontdoor.models.TimeseriesDataPoint;
import com.azure.resourcemanager.frontdoor.models.TimeseriesType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class TimeseriesInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        TimeseriesInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"endpoint\":\"tvgbmhrixkwmy\",\"startDateTimeUTC\":\"ejvegrhbpnaixex\",\"endDateTimeUTC\":\"b\",\"aggregationInterval\":\"Daily\",\"timeseriesType\":\"LatencyP95\",\"country\":\"cexdrrvqa\",\"timeseriesData\":[{\"dateTimeUTC\":\"htpwij\",\"value\":39.47339},{\"dateTimeUTC\":\"svfycxzbfv\",\"value\":37.85908},{\"dateTimeUTC\":\"rvmtgjq\",\"value\":2.3739636}]},\"location\":\"ostronz\",\"tags\":{\"cwaekrrjre\":\"gfipnsxk\",\"jglikkxwslolb\":\"fxtsgum\",\"elfk\":\"pvuzlmv\"},\"id\":\"gplcrpwjxeznoigb\",\"name\":\"njwmwkpnbsazejj\",\"type\":\"qkagfhsxt\"}")
                .toObject(TimeseriesInner.class);
        Assertions.assertEquals("ostronz", model.location());
        Assertions.assertEquals("gfipnsxk", model.tags().get("cwaekrrjre"));
        Assertions.assertEquals("tvgbmhrixkwmy", model.endpoint());
        Assertions.assertEquals("ejvegrhbpnaixex", model.startDateTimeUtc());
        Assertions.assertEquals("b", model.endDateTimeUtc());
        Assertions.assertEquals(AggregationInterval.DAILY, model.aggregationInterval());
        Assertions.assertEquals(TimeseriesType.LATENCY_P95, model.timeseriesType());
        Assertions.assertEquals("cexdrrvqa", model.country());
        Assertions.assertEquals("htpwij", model.timeseriesData().get(0).dateTimeUtc());
        Assertions.assertEquals(39.47339F, model.timeseriesData().get(0).value());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        TimeseriesInner model =
            new TimeseriesInner()
                .withLocation("ostronz")
                .withTags(mapOf("cwaekrrjre", "gfipnsxk", "jglikkxwslolb", "fxtsgum", "elfk", "pvuzlmv"))
                .withEndpoint("tvgbmhrixkwmy")
                .withStartDateTimeUtc("ejvegrhbpnaixex")
                .withEndDateTimeUtc("b")
                .withAggregationInterval(AggregationInterval.DAILY)
                .withTimeseriesType(TimeseriesType.LATENCY_P95)
                .withCountry("cexdrrvqa")
                .withTimeseriesData(
                    Arrays
                        .asList(
                            new TimeseriesDataPoint().withDateTimeUtc("htpwij").withValue(39.47339F),
                            new TimeseriesDataPoint().withDateTimeUtc("svfycxzbfv").withValue(37.85908F),
                            new TimeseriesDataPoint().withDateTimeUtc("rvmtgjq").withValue(2.3739636F)));
        model = BinaryData.fromObject(model).toObject(TimeseriesInner.class);
        Assertions.assertEquals("ostronz", model.location());
        Assertions.assertEquals("gfipnsxk", model.tags().get("cwaekrrjre"));
        Assertions.assertEquals("tvgbmhrixkwmy", model.endpoint());
        Assertions.assertEquals("ejvegrhbpnaixex", model.startDateTimeUtc());
        Assertions.assertEquals("b", model.endDateTimeUtc());
        Assertions.assertEquals(AggregationInterval.DAILY, model.aggregationInterval());
        Assertions.assertEquals(TimeseriesType.LATENCY_P95, model.timeseriesType());
        Assertions.assertEquals("cexdrrvqa", model.country());
        Assertions.assertEquals("htpwij", model.timeseriesData().get(0).dateTimeUtc());
        Assertions.assertEquals(39.47339F, model.timeseriesData().get(0).value());
    }

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