// 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.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 VirtualMachinePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        VirtualMachineProperties model = BinaryData.fromString(
            "{\"provisioningState\":\"Failed\",\"metadata\":{\"createdAt\":\"2021-01-23T06:12:50Z\",\"createdBy\":\"ygjofjdd\",\"tags\":{\"upewnwreitjzy\":\"rd\"}}}")
            .toObject(VirtualMachineProperties.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-23T06:12:50Z"), model.metadata().createdAt());
        Assertions.assertEquals("ygjofjdd", model.metadata().createdBy());
        Assertions.assertEquals("rd", model.metadata().tags().get("upewnwreitjzy"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        VirtualMachineProperties model = new VirtualMachineProperties()
            .withMetadata(new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-01-23T06:12:50Z"))
                .withCreatedBy("ygjofjdd")
                .withTags(mapOf("upewnwreitjzy", "rd")));
        model = BinaryData.fromObject(model).toObject(VirtualMachineProperties.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-23T06:12:50Z"), model.metadata().createdAt());
        Assertions.assertEquals("ygjofjdd", model.metadata().createdBy());
        Assertions.assertEquals("rd", model.metadata().tags().get("upewnwreitjzy"));
    }

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