// 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.ExportDataset;
import com.azure.resourcemanager.costmanagement.models.ExportDatasetConfiguration;
import com.azure.resourcemanager.costmanagement.models.ExportDefinition;
import com.azure.resourcemanager.costmanagement.models.ExportTimePeriod;
import com.azure.resourcemanager.costmanagement.models.ExportType;
import com.azure.resourcemanager.costmanagement.models.GranularityType;
import com.azure.resourcemanager.costmanagement.models.TimeframeType;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ExportDefinitionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ExportDefinition model =
            BinaryData
                .fromString(
                    "{\"type\":\"AmortizedCost\",\"timeframe\":\"BillingMonthToDate\",\"timePeriod\":{\"from\":\"2021-11-22T11:29:41Z\",\"to\":\"2020-12-26T05:50:43Z\"},\"dataSet\":{\"granularity\":\"Daily\",\"configuration\":{\"columns\":[\"altol\",\"ncwsob\",\"wcsdbnwdcfhucq\"]}}}")
                .toObject(ExportDefinition.class);
        Assertions.assertEquals(ExportType.AMORTIZED_COST, model.type());
        Assertions.assertEquals(TimeframeType.BILLING_MONTH_TO_DATE, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-22T11:29:41Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T05:50:43Z"), model.timePeriod().to());
        Assertions.assertEquals(GranularityType.DAILY, model.dataSet().granularity());
        Assertions.assertEquals("altol", model.dataSet().configuration().columns().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ExportDefinition model =
            new ExportDefinition()
                .withType(ExportType.AMORTIZED_COST)
                .withTimeframe(TimeframeType.BILLING_MONTH_TO_DATE)
                .withTimePeriod(
                    new ExportTimePeriod()
                        .withFrom(OffsetDateTime.parse("2021-11-22T11:29:41Z"))
                        .withTo(OffsetDateTime.parse("2020-12-26T05:50:43Z")))
                .withDataSet(
                    new ExportDataset()
                        .withGranularity(GranularityType.DAILY)
                        .withConfiguration(
                            new ExportDatasetConfiguration()
                                .withColumns(Arrays.asList("altol", "ncwsob", "wcsdbnwdcfhucq"))));
        model = BinaryData.fromObject(model).toObject(ExportDefinition.class);
        Assertions.assertEquals(ExportType.AMORTIZED_COST, model.type());
        Assertions.assertEquals(TimeframeType.BILLING_MONTH_TO_DATE, model.timeframe());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-22T11:29:41Z"), model.timePeriod().from());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T05:50:43Z"), model.timePeriod().to());
        Assertions.assertEquals(GranularityType.DAILY, model.dataSet().granularity());
        Assertions.assertEquals("altol", model.dataSet().configuration().columns().get(0));
    }
}
