// 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.models.ForecastAggregation;
import com.azure.resourcemanager.costmanagement.models.ForecastDataset;
import com.azure.resourcemanager.costmanagement.models.ForecastDatasetConfiguration;
import com.azure.resourcemanager.costmanagement.models.ForecastDefinition;
import com.azure.resourcemanager.costmanagement.models.ForecastFilter;
import com.azure.resourcemanager.costmanagement.models.ForecastTimePeriod;
import com.azure.resourcemanager.costmanagement.models.ForecastTimeframe;
import com.azure.resourcemanager.costmanagement.models.ForecastType;
import com.azure.resourcemanager.costmanagement.models.FunctionName;
import com.azure.resourcemanager.costmanagement.models.FunctionType;
import com.azure.resourcemanager.costmanagement.models.GranularityType;
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 ForecastDefinitionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ForecastDefinition model =
            BinaryData
                .fromString(
                    "{\"type\":\"Usage\",\"timeframe\":\"Custom\",\"timePeriod\":{\"from\":\"2021-06-07T11:11Z\",\"to\":\"2021-03-08T00:26:17Z\"},\"dataset\":{\"granularity\":\"Daily\",\"configuration\":{\"columns\":[\"bovpl\",\"zbhvgyuguosv\",\"kfssxqukkf\",\"l\"]},\"aggregation\":{\"xnkjzkdesl\":{\"name\":\"PreTaxCost\",\"function\":\"Sum\"}},\"filter\":{\"and\":[],\"or\":[]}},\"includeActualCost\":false,\"includeFreshPartialCost\":false}")
                .toObject(ForecastDefinition.class);
        Assertions.assertEquals(ForecastType.USAGE, model.type());
        Assertions.assertEquals(ForecastTimeframe.CUSTOM, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-07T11:11Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-08T00:26:17Z"), model.timePeriod().to());
        Assertions.assertEquals(GranularityType.DAILY, model.dataset().granularity());
        Assertions.assertEquals("bovpl", model.dataset().configuration().columns().get(0));
        Assertions.assertEquals(FunctionName.PRE_TAX_COST, model.dataset().aggregation().get("xnkjzkdesl").name());
        Assertions.assertEquals(FunctionType.SUM, model.dataset().aggregation().get("xnkjzkdesl").function());
        Assertions.assertEquals(false, model.includeActualCost());
        Assertions.assertEquals(false, model.includeFreshPartialCost());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ForecastDefinition model =
            new ForecastDefinition()
                .withType(ForecastType.USAGE)
                .withTimeframe(ForecastTimeframe.CUSTOM)
                .withTimePeriod(
                    new ForecastTimePeriod()
                        .withFrom(OffsetDateTime.parse("2021-06-07T11:11Z"))
                        .withTo(OffsetDateTime.parse("2021-03-08T00:26:17Z")))
                .withDataset(
                    new ForecastDataset()
                        .withGranularity(GranularityType.DAILY)
                        .withConfiguration(
                            new ForecastDatasetConfiguration()
                                .withColumns(Arrays.asList("bovpl", "zbhvgyuguosv", "kfssxqukkf", "l")))
                        .withAggregation(
                            mapOf(
                                "xnkjzkdesl",
                                new ForecastAggregation()
                                    .withName(FunctionName.PRE_TAX_COST)
                                    .withFunction(FunctionType.SUM)))
                        .withFilter(new ForecastFilter().withAnd(Arrays.asList()).withOr(Arrays.asList())))
                .withIncludeActualCost(false)
                .withIncludeFreshPartialCost(false);
        model = BinaryData.fromObject(model).toObject(ForecastDefinition.class);
        Assertions.assertEquals(ForecastType.USAGE, model.type());
        Assertions.assertEquals(ForecastTimeframe.CUSTOM, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-07T11:11Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-08T00:26:17Z"), model.timePeriod().to());
        Assertions.assertEquals(GranularityType.DAILY, model.dataset().granularity());
        Assertions.assertEquals("bovpl", model.dataset().configuration().columns().get(0));
        Assertions.assertEquals(FunctionName.PRE_TAX_COST, model.dataset().aggregation().get("xnkjzkdesl").name());
        Assertions.assertEquals(FunctionType.SUM, model.dataset().aggregation().get("xnkjzkdesl").function());
        Assertions.assertEquals(false, model.includeActualCost());
        Assertions.assertEquals(false, model.includeFreshPartialCost());
    }

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