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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.FormulaInner;
import com.azure.resourcemanager.devtestlabs.models.FormulaPropertiesFromVm;
import com.azure.resourcemanager.devtestlabs.models.LabVirtualMachineCreationParameter;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class FormulaInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        FormulaInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"description\":\"znqntoru\",\"author\":\"gsahmkycgrauw\",\"osType\":\"etaebu\",\"creationDate\":\"2021-09-21T03:41:44Z\",\"formulaContent\":{\"name\":\"vsmzlxwab\",\"location\":\"oefki\",\"tags\":{\"gkfbtndoaong\":\"tpuqujmq\",\"tcje\":\"jcntuj\",\"zfoqouicybxar\":\"ftwwaezkojvdc\"}},\"vm\":{\"labVmId\":\"zuf\"},\"provisioningState\":\"ciqopidoa\",\"uniqueIdentifier\":\"iodhkhazxkhnz\"},\"location\":\"onlwntoeg\",\"tags\":{\"kszzcmrvexztv\":\"wbw\",\"gsfraoyzkoow\":\"t\",\"aldsy\":\"lmnguxaw\",\"znkbykutwpfhpagm\":\"uximerqfobw\"},\"id\":\"r\",\"name\":\"kdsnfdsdoakgtdl\",\"type\":\"kkze\"}")
                .toObject(FormulaInner.class);
        Assertions.assertEquals("onlwntoeg", model.location());
        Assertions.assertEquals("wbw", model.tags().get("kszzcmrvexztv"));
        Assertions.assertEquals("znqntoru", model.description());
        Assertions.assertEquals("etaebu", model.osType());
        Assertions.assertEquals("vsmzlxwab", model.formulaContent().name());
        Assertions.assertEquals("oefki", model.formulaContent().location());
        Assertions.assertEquals("tpuqujmq", model.formulaContent().tags().get("gkfbtndoaong"));
        Assertions.assertEquals("zuf", model.vm().labVmId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        FormulaInner model =
            new FormulaInner()
                .withLocation("onlwntoeg")
                .withTags(
                    mapOf(
                        "kszzcmrvexztv",
                        "wbw",
                        "gsfraoyzkoow",
                        "t",
                        "aldsy",
                        "lmnguxaw",
                        "znkbykutwpfhpagm",
                        "uximerqfobw"))
                .withDescription("znqntoru")
                .withOsType("etaebu")
                .withFormulaContent(
                    new LabVirtualMachineCreationParameter()
                        .withName("vsmzlxwab")
                        .withLocation("oefki")
                        .withTags(
                            mapOf("gkfbtndoaong", "tpuqujmq", "tcje", "jcntuj", "zfoqouicybxar", "ftwwaezkojvdc")))
                .withVm(new FormulaPropertiesFromVm().withLabVmId("zuf"));
        model = BinaryData.fromObject(model).toObject(FormulaInner.class);
        Assertions.assertEquals("onlwntoeg", model.location());
        Assertions.assertEquals("wbw", model.tags().get("kszzcmrvexztv"));
        Assertions.assertEquals("znqntoru", model.description());
        Assertions.assertEquals("etaebu", model.osType());
        Assertions.assertEquals("vsmzlxwab", model.formulaContent().name());
        Assertions.assertEquals("oefki", model.formulaContent().location());
        Assertions.assertEquals("tpuqujmq", model.formulaContent().tags().get("gkfbtndoaong"));
        Assertions.assertEquals("zuf", model.vm().labVmId());
    }

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