// 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.fluent.models.ResourceRateCardInfoInner;
import com.azure.resourcemanager.commerce.models.MeterInfo;
import com.azure.resourcemanager.commerce.models.OfferTermInfoAutoGenerated;
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 ResourceRateCardInfoInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ResourceRateCardInfoInner model =
            BinaryData
                .fromString(
                    "{\"Currency\":\"oqpsoa\",\"Locale\":\"tazak\",\"IsTaxIncluded\":true,\"OfferTerms\":[{\"Name\":\"OfferTermInfoAutoGenerated\",\"EffectiveDate\":\"2021-06-15T07:28:27Z\"},{\"Name\":\"OfferTermInfoAutoGenerated\",\"EffectiveDate\":\"2021-10-01T21:39:25Z\"},{\"Name\":\"OfferTermInfoAutoGenerated\",\"EffectiveDate\":\"2021-02-13T07:50:35Z\"},{\"Name\":\"OfferTermInfoAutoGenerated\",\"EffectiveDate\":\"2021-07-14T10:08:19Z\"}],\"Meters\":[{\"MeterId\":\"21c454b4-9be1-44a4-8275-74ca26236155\",\"MeterName\":\"gexpaojakhmsbz\",\"MeterCategory\":\"crzevdphlx\",\"MeterSubCategory\":\"lthqtrgqjbp\",\"Unit\":\"fsinzgvfcjrwzoxx\",\"MeterTags\":[\"elluwfziton\",\"eqfpj\",\"jlxofpdvhpfxxyp\",\"ninmayhuyb\"],\"MeterRegion\":\"podepoo\",\"MeterRates\":{\"vamih\":94.223724,\"gnarxzxtheo\":92.43863,\"si\":35.96248},\"EffectiveDate\":\"2021-11-04T11:49:42Z\",\"IncludedQuantity\":90.02525},{\"MeterId\":\"7c95010f-59ae-4879-bbc0-077e4df6540f\",\"MeterName\":\"qi\",\"MeterCategory\":\"hungbwjzrnf\",\"MeterSubCategory\":\"xgispemvtzfkufu\",\"Unit\":\"jofxqe\",\"MeterTags\":[\"aeqjhqjbasvms\"],\"MeterRegion\":\"qulngsntnbybkzgc\",\"MeterRates\":{\"lxxwrljdouskc\":57.128227,\"kocrcjdkwtnhx\":70.357445},\"EffectiveDate\":\"2020-12-31T19:07:05Z\",\"IncludedQuantity\":30.74364}]}")
                .toObject(ResourceRateCardInfoInner.class);
        Assertions.assertEquals("oqpsoa", model.currency());
        Assertions.assertEquals("tazak", model.locale());
        Assertions.assertEquals(true, model.isTaxIncluded());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-06-15T07:28:27Z"), model.offerTerms().get(0).effectiveDate());
        Assertions
            .assertEquals(UUID.fromString("21c454b4-9be1-44a4-8275-74ca26236155"), model.meters().get(0).meterId());
        Assertions.assertEquals("gexpaojakhmsbz", model.meters().get(0).meterName());
        Assertions.assertEquals("crzevdphlx", model.meters().get(0).meterCategory());
        Assertions.assertEquals("lthqtrgqjbp", model.meters().get(0).meterSubCategory());
        Assertions.assertEquals("fsinzgvfcjrwzoxx", model.meters().get(0).unit());
        Assertions.assertEquals("elluwfziton", model.meters().get(0).meterTags().get(0));
        Assertions.assertEquals("podepoo", model.meters().get(0).meterRegion());
        Assertions.assertEquals(94.223724f, model.meters().get(0).meterRates().get("vamih"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-04T11:49:42Z"), model.meters().get(0).effectiveDate());
        Assertions.assertEquals(90.02525F, model.meters().get(0).includedQuantity());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ResourceRateCardInfoInner model =
            new ResourceRateCardInfoInner()
                .withCurrency("oqpsoa")
                .withLocale("tazak")
                .withIsTaxIncluded(true)
                .withOfferTerms(
                    Arrays
                        .asList(
                            new OfferTermInfoAutoGenerated()
                                .withEffectiveDate(OffsetDateTime.parse("2021-06-15T07:28:27Z")),
                            new OfferTermInfoAutoGenerated()
                                .withEffectiveDate(OffsetDateTime.parse("2021-10-01T21:39:25Z")),
                            new OfferTermInfoAutoGenerated()
                                .withEffectiveDate(OffsetDateTime.parse("2021-02-13T07:50:35Z")),
                            new OfferTermInfoAutoGenerated()
                                .withEffectiveDate(OffsetDateTime.parse("2021-07-14T10:08:19Z"))))
                .withMeters(
                    Arrays
                        .asList(
                            new MeterInfo()
                                .withMeterId(UUID.fromString("21c454b4-9be1-44a4-8275-74ca26236155"))
                                .withMeterName("gexpaojakhmsbz")
                                .withMeterCategory("crzevdphlx")
                                .withMeterSubCategory("lthqtrgqjbp")
                                .withUnit("fsinzgvfcjrwzoxx")
                                .withMeterTags(Arrays.asList("elluwfziton", "eqfpj", "jlxofpdvhpfxxyp", "ninmayhuyb"))
                                .withMeterRegion("podepoo")
                                .withMeterRates(mapOf("vamih", 94.223724f, "gnarxzxtheo", 92.43863f, "si", 35.96248f))
                                .withEffectiveDate(OffsetDateTime.parse("2021-11-04T11:49:42Z"))
                                .withIncludedQuantity(90.02525F),
                            new MeterInfo()
                                .withMeterId(UUID.fromString("7c95010f-59ae-4879-bbc0-077e4df6540f"))
                                .withMeterName("qi")
                                .withMeterCategory("hungbwjzrnf")
                                .withMeterSubCategory("xgispemvtzfkufu")
                                .withUnit("jofxqe")
                                .withMeterTags(Arrays.asList("aeqjhqjbasvms"))
                                .withMeterRegion("qulngsntnbybkzgc")
                                .withMeterRates(mapOf("lxxwrljdouskc", 57.128227f, "kocrcjdkwtnhx", 70.357445f))
                                .withEffectiveDate(OffsetDateTime.parse("2020-12-31T19:07:05Z"))
                                .withIncludedQuantity(30.74364F)));
        model = BinaryData.fromObject(model).toObject(ResourceRateCardInfoInner.class);
        Assertions.assertEquals("oqpsoa", model.currency());
        Assertions.assertEquals("tazak", model.locale());
        Assertions.assertEquals(true, model.isTaxIncluded());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-06-15T07:28:27Z"), model.offerTerms().get(0).effectiveDate());
        Assertions
            .assertEquals(UUID.fromString("21c454b4-9be1-44a4-8275-74ca26236155"), model.meters().get(0).meterId());
        Assertions.assertEquals("gexpaojakhmsbz", model.meters().get(0).meterName());
        Assertions.assertEquals("crzevdphlx", model.meters().get(0).meterCategory());
        Assertions.assertEquals("lthqtrgqjbp", model.meters().get(0).meterSubCategory());
        Assertions.assertEquals("fsinzgvfcjrwzoxx", model.meters().get(0).unit());
        Assertions.assertEquals("elluwfziton", model.meters().get(0).meterTags().get(0));
        Assertions.assertEquals("podepoo", model.meters().get(0).meterRegion());
        Assertions.assertEquals(94.223724f, model.meters().get(0).meterRates().get("vamih"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-04T11:49:42Z"), model.meters().get(0).effectiveDate());
        Assertions.assertEquals(90.02525F, model.meters().get(0).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;
    }
}
