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

package com.azure.resourcemanager.cognitiveservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.cognitiveservices.fluent.models.UsageListResultInner;
import com.azure.resourcemanager.cognitiveservices.models.MetricName;
import com.azure.resourcemanager.cognitiveservices.models.QuotaUsageStatus;
import com.azure.resourcemanager.cognitiveservices.models.UnitType;
import com.azure.resourcemanager.cognitiveservices.models.Usage;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class UsageListResultInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        UsageListResultInner model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"unit\":\"Seconds\",\"name\":{\"value\":\"jpqyegu\",\"localizedValue\":\"hb\"},\"quotaPeriod\":\"hejjz\",\"limit\":70.33604475808148,\"currentValue\":63.32915383545625,\"nextResetTime\":\"slfhotwm\",\"status\":\"InOverage\"},{\"unit\":\"Milliseconds\",\"name\":{\"value\":\"jnpg\",\"localizedValue\":\"ftadehxnltyfs\"},\"quotaPeriod\":\"pusuesn\",\"limit\":42.583161707778174,\"currentValue\":20.416251033380174,\"nextResetTime\":\"orxzdmohctbqvud\",\"status\":\"Blocked\"},{\"unit\":\"Count\",\"name\":{\"value\":\"owgujjugwdkcglhs\",\"localizedValue\":\"zj\"},\"quotaPeriod\":\"ggd\",\"limit\":92.2174087854439,\"currentValue\":3.8497339257224095,\"nextResetTime\":\"ofqweykhmenevfye\",\"status\":\"Blocked\"},{\"unit\":\"Bytes\",\"name\":{\"value\":\"i\",\"localizedValue\":\"yvdcsitynnaa\"},\"quotaPeriod\":\"ectehf\",\"limit\":43.32844185113748,\"currentValue\":61.13135450146281,\"nextResetTime\":\"vhezrkgqhcj\",\"status\":\"Unknown\"}]}")
                .toObject(UsageListResultInner.class);
        Assertions.assertEquals(UnitType.SECONDS, model.value().get(0).unit());
        Assertions.assertEquals("jpqyegu", model.value().get(0).name().value());
        Assertions.assertEquals("hb", model.value().get(0).name().localizedValue());
        Assertions.assertEquals("hejjz", model.value().get(0).quotaPeriod());
        Assertions.assertEquals(70.33604475808148D, model.value().get(0).limit());
        Assertions.assertEquals(63.32915383545625D, model.value().get(0).currentValue());
        Assertions.assertEquals("slfhotwm", model.value().get(0).nextResetTime());
        Assertions.assertEquals(QuotaUsageStatus.IN_OVERAGE, model.value().get(0).status());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        UsageListResultInner model =
            new UsageListResultInner()
                .withValue(
                    Arrays
                        .asList(
                            new Usage()
                                .withUnit(UnitType.SECONDS)
                                .withName(new MetricName().withValue("jpqyegu").withLocalizedValue("hb"))
                                .withQuotaPeriod("hejjz")
                                .withLimit(70.33604475808148D)
                                .withCurrentValue(63.32915383545625D)
                                .withNextResetTime("slfhotwm")
                                .withStatus(QuotaUsageStatus.IN_OVERAGE),
                            new Usage()
                                .withUnit(UnitType.MILLISECONDS)
                                .withName(new MetricName().withValue("jnpg").withLocalizedValue("ftadehxnltyfs"))
                                .withQuotaPeriod("pusuesn")
                                .withLimit(42.583161707778174D)
                                .withCurrentValue(20.416251033380174D)
                                .withNextResetTime("orxzdmohctbqvud")
                                .withStatus(QuotaUsageStatus.BLOCKED),
                            new Usage()
                                .withUnit(UnitType.COUNT)
                                .withName(new MetricName().withValue("owgujjugwdkcglhs").withLocalizedValue("zj"))
                                .withQuotaPeriod("ggd")
                                .withLimit(92.2174087854439D)
                                .withCurrentValue(3.8497339257224095D)
                                .withNextResetTime("ofqweykhmenevfye")
                                .withStatus(QuotaUsageStatus.BLOCKED),
                            new Usage()
                                .withUnit(UnitType.BYTES)
                                .withName(new MetricName().withValue("i").withLocalizedValue("yvdcsitynnaa"))
                                .withQuotaPeriod("ectehf")
                                .withLimit(43.32844185113748D)
                                .withCurrentValue(61.13135450146281D)
                                .withNextResetTime("vhezrkgqhcj")
                                .withStatus(QuotaUsageStatus.UNKNOWN)));
        model = BinaryData.fromObject(model).toObject(UsageListResultInner.class);
        Assertions.assertEquals(UnitType.SECONDS, model.value().get(0).unit());
        Assertions.assertEquals("jpqyegu", model.value().get(0).name().value());
        Assertions.assertEquals("hb", model.value().get(0).name().localizedValue());
        Assertions.assertEquals("hejjz", model.value().get(0).quotaPeriod());
        Assertions.assertEquals(70.33604475808148D, model.value().get(0).limit());
        Assertions.assertEquals(63.32915383545625D, model.value().get(0).currentValue());
        Assertions.assertEquals("slfhotwm", model.value().get(0).nextResetTime());
        Assertions.assertEquals(QuotaUsageStatus.IN_OVERAGE, model.value().get(0).status());
    }
}
