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

package com.azure.resourcemanager.costmanagement.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.costmanagement.fluent.models.ViewProperties;
import com.azure.resourcemanager.costmanagement.models.AccumulatedType;
import com.azure.resourcemanager.costmanagement.models.ChartType;
import com.azure.resourcemanager.costmanagement.models.KpiProperties;
import com.azure.resourcemanager.costmanagement.models.KpiType;
import com.azure.resourcemanager.costmanagement.models.MetricType;
import com.azure.resourcemanager.costmanagement.models.PivotProperties;
import com.azure.resourcemanager.costmanagement.models.PivotType;
import com.azure.resourcemanager.costmanagement.models.ReportConfigDataset;
import com.azure.resourcemanager.costmanagement.models.ReportConfigTimePeriod;
import com.azure.resourcemanager.costmanagement.models.ReportGranularityType;
import com.azure.resourcemanager.costmanagement.models.ReportTimeframeType;
import com.azure.resourcemanager.costmanagement.models.ReportType;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ViewPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ViewProperties model =
            BinaryData
                .fromString(
                    "{\"displayName\":\"mrldhu\",\"scope\":\"zzd\",\"createdOn\":\"2021-02-05T21:48:33Z\",\"modifiedOn\":\"2021-07-06T17:21:07Z\",\"dateRange\":\"cdgea\",\"currency\":\"gphuticndvka\",\"query\":{\"type\":\"Usage\",\"timeframe\":\"YearToDate\",\"timePeriod\":{\"from\":\"2021-02-22T11:39:16Z\",\"to\":\"2021-02-09T20:02:29Z\"},\"dataSet\":{\"granularity\":\"Daily\",\"aggregation\":{},\"grouping\":[],\"sorting\":[]},\"includeMonetaryCommitment\":true},\"chart\":\"Area\",\"accumulated\":\"false\",\"metric\":\"ActualCost\",\"kpis\":[{\"type\":\"Budget\",\"id\":\"kgiawxklryplwck\",\"enabled\":false},{\"type\":\"Budget\",\"id\":\"nddhsgcbacph\",\"enabled\":false},{\"type\":\"Forecast\",\"id\":\"nqgoulzndli\",\"enabled\":false},{\"type\":\"Forecast\",\"id\":\"fgibmadgakeq\",\"enabled\":false}],\"pivots\":[{\"type\":\"TagKey\",\"name\":\"e\"},{\"type\":\"Dimension\",\"name\":\"bciqfouflm\"},{\"type\":\"Dimension\",\"name\":\"smodmgloug\"},{\"type\":\"TagKey\",\"name\":\"tmut\"}]}")
                .toObject(ViewProperties.class);
        Assertions.assertEquals("mrldhu", model.displayName());
        Assertions.assertEquals("zzd", model.scope());
        Assertions.assertEquals(ChartType.AREA, model.chart());
        Assertions.assertEquals(AccumulatedType.FALSE, model.accumulated());
        Assertions.assertEquals(MetricType.ACTUAL_COST, model.metric());
        Assertions.assertEquals(KpiType.BUDGET, model.kpis().get(0).type());
        Assertions.assertEquals("kgiawxklryplwck", model.kpis().get(0).id());
        Assertions.assertEquals(false, model.kpis().get(0).enabled());
        Assertions.assertEquals(PivotType.TAG_KEY, model.pivots().get(0).type());
        Assertions.assertEquals("e", model.pivots().get(0).name());
        Assertions.assertEquals(ReportType.USAGE, model.type());
        Assertions.assertEquals(ReportTimeframeType.YEAR_TO_DATE, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-22T11:39:16Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-09T20:02:29Z"), model.timePeriod().to());
        Assertions.assertEquals(ReportGranularityType.DAILY, model.dataSet().granularity());
        Assertions.assertEquals(true, model.includeMonetaryCommitment());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ViewProperties model =
            new ViewProperties()
                .withDisplayName("mrldhu")
                .withScope("zzd")
                .withChart(ChartType.AREA)
                .withAccumulated(AccumulatedType.FALSE)
                .withMetric(MetricType.ACTUAL_COST)
                .withKpis(
                    Arrays
                        .asList(
                            new KpiProperties().withType(KpiType.BUDGET).withId("kgiawxklryplwck").withEnabled(false),
                            new KpiProperties().withType(KpiType.BUDGET).withId("nddhsgcbacph").withEnabled(false),
                            new KpiProperties().withType(KpiType.FORECAST).withId("nqgoulzndli").withEnabled(false),
                            new KpiProperties().withType(KpiType.FORECAST).withId("fgibmadgakeq").withEnabled(false)))
                .withPivots(
                    Arrays
                        .asList(
                            new PivotProperties().withType(PivotType.TAG_KEY).withName("e"),
                            new PivotProperties().withType(PivotType.DIMENSION).withName("bciqfouflm"),
                            new PivotProperties().withType(PivotType.DIMENSION).withName("smodmgloug"),
                            new PivotProperties().withType(PivotType.TAG_KEY).withName("tmut")))
                .withType(ReportType.USAGE)
                .withTimeframe(ReportTimeframeType.YEAR_TO_DATE)
                .withTimePeriod(
                    new ReportConfigTimePeriod()
                        .withFrom(OffsetDateTime.parse("2021-02-22T11:39:16Z"))
                        .withTo(OffsetDateTime.parse("2021-02-09T20:02:29Z")))
                .withDataSet(
                    new ReportConfigDataset()
                        .withGranularity(ReportGranularityType.DAILY)
                        .withAggregation(mapOf())
                        .withGrouping(Arrays.asList())
                        .withSorting(Arrays.asList()))
                .withIncludeMonetaryCommitment(true);
        model = BinaryData.fromObject(model).toObject(ViewProperties.class);
        Assertions.assertEquals("mrldhu", model.displayName());
        Assertions.assertEquals("zzd", model.scope());
        Assertions.assertEquals(ChartType.AREA, model.chart());
        Assertions.assertEquals(AccumulatedType.FALSE, model.accumulated());
        Assertions.assertEquals(MetricType.ACTUAL_COST, model.metric());
        Assertions.assertEquals(KpiType.BUDGET, model.kpis().get(0).type());
        Assertions.assertEquals("kgiawxklryplwck", model.kpis().get(0).id());
        Assertions.assertEquals(false, model.kpis().get(0).enabled());
        Assertions.assertEquals(PivotType.TAG_KEY, model.pivots().get(0).type());
        Assertions.assertEquals("e", model.pivots().get(0).name());
        Assertions.assertEquals(ReportType.USAGE, model.type());
        Assertions.assertEquals(ReportTimeframeType.YEAR_TO_DATE, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-22T11:39:16Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-09T20:02:29Z"), model.timePeriod().to());
        Assertions.assertEquals(ReportGranularityType.DAILY, model.dataSet().granularity());
        Assertions.assertEquals(true, model.includeMonetaryCommitment());
    }

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