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

package com.azure.resourcemanager.commerce.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.commerce.models.MeterInfo;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Assertions;

public final class MeterInfoTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MeterInfo model =
            BinaryData
                .fromString(
                    "{\"MeterId\":\"02c5a81b-ee19-4c50-bb4c-6805c59050b2\",\"MeterName\":\"gls\",\"MeterCategory\":\"inqpjwnzll\",\"MeterSubCategory\":\"mppeebvmgxs\",\"Unit\":\"kyqduujit\",\"MeterTags\":[\"zdzevndh\",\"rwpdappdsbdkvwrw\"],\"MeterRegion\":\"eusnhutj\",\"MeterRates\":{\"rl\":33.49618,\"ugjzzdatqxhocdge\":86.19471,\"lgphu\":56.39705,\"cndvkaozwyiftyhx\":89.55463},\"EffectiveDate\":\"2021-01-28T13:33:14Z\",\"IncludedQuantity\":5.188751}")
                .toObject(MeterInfo.class);
        Assertions.assertEquals(UUID.fromString("02c5a81b-ee19-4c50-bb4c-6805c59050b2"), model.meterId());
        Assertions.assertEquals("gls", model.meterName());
        Assertions.assertEquals("inqpjwnzll", model.meterCategory());
        Assertions.assertEquals("mppeebvmgxs", model.meterSubCategory());
        Assertions.assertEquals("kyqduujit", model.unit());
        Assertions.assertEquals("zdzevndh", model.meterTags().get(0));
        Assertions.assertEquals("eusnhutj", model.meterRegion());
        Assertions.assertEquals(33.49618f, model.meterRates().get("rl"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-28T13:33:14Z"), model.effectiveDate());
        Assertions.assertEquals(5.188751F, model.includedQuantity());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MeterInfo model =
            new MeterInfo()
                .withMeterId(UUID.fromString("02c5a81b-ee19-4c50-bb4c-6805c59050b2"))
                .withMeterName("gls")
                .withMeterCategory("inqpjwnzll")
                .withMeterSubCategory("mppeebvmgxs")
                .withUnit("kyqduujit")
                .withMeterTags(Arrays.asList("zdzevndh", "rwpdappdsbdkvwrw"))
                .withMeterRegion("eusnhutj")
                .withMeterRates(
                    mapOf(
                        "rl",
                        33.49618f,
                        "ugjzzdatqxhocdge",
                        86.19471f,
                        "lgphu",
                        56.39705f,
                        "cndvkaozwyiftyhx",
                        89.55463f))
                .withEffectiveDate(OffsetDateTime.parse("2021-01-28T13:33:14Z"))
                .withIncludedQuantity(5.188751F);
        model = BinaryData.fromObject(model).toObject(MeterInfo.class);
        Assertions.assertEquals(UUID.fromString("02c5a81b-ee19-4c50-bb4c-6805c59050b2"), model.meterId());
        Assertions.assertEquals("gls", model.meterName());
        Assertions.assertEquals("inqpjwnzll", model.meterCategory());
        Assertions.assertEquals("mppeebvmgxs", model.meterSubCategory());
        Assertions.assertEquals("kyqduujit", model.unit());
        Assertions.assertEquals("zdzevndh", model.meterTags().get(0));
        Assertions.assertEquals("eusnhutj", model.meterRegion());
        Assertions.assertEquals(33.49618f, model.meterRates().get("rl"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-28T13:33:14Z"), model.effectiveDate());
        Assertions.assertEquals(5.188751F, model.includedQuantity());
    }

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