// 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.CommitmentPlanInner;
import com.azure.resourcemanager.cognitiveservices.models.CommitmentPeriod;
import com.azure.resourcemanager.cognitiveservices.models.CommitmentPlanProperties;
import com.azure.resourcemanager.cognitiveservices.models.HostingModel;
import com.azure.resourcemanager.cognitiveservices.models.Sku;
import com.azure.resourcemanager.cognitiveservices.models.SkuTier;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class CommitmentPlanInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CommitmentPlanInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"ulpjr\",\"kind\":\"ag\",\"sku\":{\"name\":\"vimjwos\",\"tier\":\"Premium\",\"size\":\"tcs\",\"family\":\"cktqumiekkezzi\",\"capacity\":270423154},\"tags\":{\"qidbqfatpxllrxcy\":\"jhdgqggebdunyga\",\"dmjsjqb\":\"moadsuvarmy\"},\"location\":\"hyxxrwlycoduhpk\",\"properties\":{\"provisioningState\":\"Failed\",\"commitmentPlanGuid\":\"areqna\",\"hostingModel\":\"ConnectedContainer\",\"planType\":\"gjhkycubeddg\",\"current\":{\"tier\":\"fwqmzqalkrmn\",\"count\":1174672424,\"startDate\":\"acqqudfnbyxbaaab\",\"endDate\":\"vayffimrzrt\"},\"autoRenew\":true,\"next\":{\"tier\":\"sexnevfdnw\",\"count\":2059840008,\"startDate\":\"zsyyceuzso\",\"endDate\":\"judpfrxt\"},\"last\":{\"tier\":\"zvaytdwkqbr\",\"count\":1725477484,\"startDate\":\"xhexiilivpdti\",\"endDate\":\"q\"}},\"id\":\"d\",\"name\":\"oaxoruzfgsqu\",\"type\":\"fxrxxle\"}")
                .toObject(CommitmentPlanInner.class);
        Assertions.assertEquals("ag", model.kind());
        Assertions.assertEquals("vimjwos", model.sku().name());
        Assertions.assertEquals(SkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals("tcs", model.sku().size());
        Assertions.assertEquals("cktqumiekkezzi", model.sku().family());
        Assertions.assertEquals(270423154, model.sku().capacity());
        Assertions.assertEquals("jhdgqggebdunyga", model.tags().get("qidbqfatpxllrxcy"));
        Assertions.assertEquals("hyxxrwlycoduhpk", model.location());
        Assertions.assertEquals("areqna", model.properties().commitmentPlanGuid());
        Assertions.assertEquals(HostingModel.CONNECTED_CONTAINER, model.properties().hostingModel());
        Assertions.assertEquals("gjhkycubeddg", model.properties().planType());
        Assertions.assertEquals("fwqmzqalkrmn", model.properties().current().tier());
        Assertions.assertEquals(1174672424, model.properties().current().count());
        Assertions.assertEquals(true, model.properties().autoRenew());
        Assertions.assertEquals("sexnevfdnw", model.properties().next().tier());
        Assertions.assertEquals(2059840008, model.properties().next().count());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CommitmentPlanInner model =
            new CommitmentPlanInner()
                .withKind("ag")
                .withSku(
                    new Sku()
                        .withName("vimjwos")
                        .withTier(SkuTier.PREMIUM)
                        .withSize("tcs")
                        .withFamily("cktqumiekkezzi")
                        .withCapacity(270423154))
                .withTags(mapOf("qidbqfatpxllrxcy", "jhdgqggebdunyga", "dmjsjqb", "moadsuvarmy"))
                .withLocation("hyxxrwlycoduhpk")
                .withProperties(
                    new CommitmentPlanProperties()
                        .withCommitmentPlanGuid("areqna")
                        .withHostingModel(HostingModel.CONNECTED_CONTAINER)
                        .withPlanType("gjhkycubeddg")
                        .withCurrent(new CommitmentPeriod().withTier("fwqmzqalkrmn").withCount(1174672424))
                        .withAutoRenew(true)
                        .withNext(new CommitmentPeriod().withTier("sexnevfdnw").withCount(2059840008)));
        model = BinaryData.fromObject(model).toObject(CommitmentPlanInner.class);
        Assertions.assertEquals("ag", model.kind());
        Assertions.assertEquals("vimjwos", model.sku().name());
        Assertions.assertEquals(SkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals("tcs", model.sku().size());
        Assertions.assertEquals("cktqumiekkezzi", model.sku().family());
        Assertions.assertEquals(270423154, model.sku().capacity());
        Assertions.assertEquals("jhdgqggebdunyga", model.tags().get("qidbqfatpxllrxcy"));
        Assertions.assertEquals("hyxxrwlycoduhpk", model.location());
        Assertions.assertEquals("areqna", model.properties().commitmentPlanGuid());
        Assertions.assertEquals(HostingModel.CONNECTED_CONTAINER, model.properties().hostingModel());
        Assertions.assertEquals("gjhkycubeddg", model.properties().planType());
        Assertions.assertEquals("fwqmzqalkrmn", model.properties().current().tier());
        Assertions.assertEquals(1174672424, model.properties().current().count());
        Assertions.assertEquals(true, model.properties().autoRenew());
        Assertions.assertEquals("sexnevfdnw", model.properties().next().tier());
        Assertions.assertEquals(2059840008, model.properties().next().count());
    }

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