// 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.StorageAccountProperties;
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 StorageAccountPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        StorageAccountProperties model = BinaryData.fromString(
            "{\"provisioningState\":\"Canceled\",\"metadata\":{\"createdAt\":\"2021-08-18T11:52:54Z\",\"createdBy\":\"hkryhtn\",\"tags\":{\"okjye\":\"zw\",\"jnchgej\":\"kkvnipjox\",\"huxinpmqnj\":\"podmailzydehojwy\"}}}")
            .toObject(StorageAccountProperties.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-18T11:52:54Z"), model.metadata().createdAt());
        Assertions.assertEquals("hkryhtn", model.metadata().createdBy());
        Assertions.assertEquals("zw", model.metadata().tags().get("okjye"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        StorageAccountProperties model = new StorageAccountProperties()
            .withMetadata(new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-08-18T11:52:54Z"))
                .withCreatedBy("hkryhtn")
                .withTags(mapOf("okjye", "zw", "jnchgej", "kkvnipjox", "huxinpmqnj", "podmailzydehojwy")));
        model = BinaryData.fromObject(model).toObject(StorageAccountProperties.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-18T11:52:54Z"), model.metadata().createdAt());
        Assertions.assertEquals("hkryhtn", model.metadata().createdBy());
        Assertions.assertEquals("zw", model.metadata().tags().get("okjye"));
    }

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