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

package azure.resourcemanager.multiservicesharedmodels.combined.generated;

import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner;
import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata;
import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties;
import com.azure.core.util.BinaryData;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class VirtualMachineInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        VirtualMachineInner model = BinaryData.fromString(
            "{\"properties\":{\"provisioningState\":\"Succeeded\",\"metadata\":{\"createdAt\":\"2021-07-30T08:26:42Z\",\"createdBy\":\"jxpybczmeh\",\"tags\":{\"phrupidgsybbejhp\":\"opb\",\"ioq\":\"oycmsxaobhdxbmt\",\"p\":\"zehtbmu\",\"hwlrx\":\"wnoi\"}}},\"location\":\"qsoqijgkd\",\"tags\":{\"qqjnqgl\":\"azlobcufpdznrbt\",\"foooj\":\"qgn\",\"saagdf\":\"wifsq\"},\"id\":\"glzlhjxrifkwmrv\",\"name\":\"tsizntocipaoua\",\"type\":\"psqucmpoyf\"}")
            .toObject(VirtualMachineInner.class);
        Assertions.assertEquals("qsoqijgkd", model.location());
        Assertions.assertEquals("azlobcufpdznrbt", model.tags().get("qqjnqgl"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-30T08:26:42Z"),
            model.properties().metadata().createdAt());
        Assertions.assertEquals("jxpybczmeh", model.properties().metadata().createdBy());
        Assertions.assertEquals("opb", model.properties().metadata().tags().get("phrupidgsybbejhp"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        VirtualMachineInner model
            = new VirtualMachineInner().withLocation("qsoqijgkd")
                .withTags(mapOf("qqjnqgl", "azlobcufpdznrbt", "foooj", "qgn", "saagdf", "wifsq"))
                .withProperties(new VirtualMachineProperties().withMetadata(new SharedMetadata()
                    .withCreatedAt(OffsetDateTime.parse("2021-07-30T08:26:42Z"))
                    .withCreatedBy("jxpybczmeh")
                    .withTags(
                        mapOf("phrupidgsybbejhp", "opb", "ioq", "oycmsxaobhdxbmt", "p", "zehtbmu", "hwlrx", "wnoi"))));
        model = BinaryData.fromObject(model).toObject(VirtualMachineInner.class);
        Assertions.assertEquals("qsoqijgkd", model.location());
        Assertions.assertEquals("azlobcufpdznrbt", model.tags().get("qqjnqgl"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-30T08:26:42Z"),
            model.properties().metadata().createdAt());
        Assertions.assertEquals("jxpybczmeh", model.properties().metadata().createdBy());
        Assertions.assertEquals("opb", model.properties().metadata().tags().get("phrupidgsybbejhp"));
    }

    // Use "Map.of" if available
    @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;
    }
}
