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

package com.azure.resourcemanager.deviceupdate.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.deviceupdate.fluent.models.InstanceInner;
import com.azure.resourcemanager.deviceupdate.models.AuthenticationType;
import com.azure.resourcemanager.deviceupdate.models.DiagnosticStorageProperties;
import com.azure.resourcemanager.deviceupdate.models.IotHubSettings;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class InstanceInnerTests {
    @Test
    public void testDeserialize() {
        InstanceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Canceled\",\"accountName\":\"bmbexppbhtqqro\",\"iotHubs\":[{\"resourceId\":\"fpsalgbqu\"}],\"enableDiagnostics\":true,\"diagnosticStorageProperties\":{\"authenticationType\":\"KeyBased\",\"connectionString\":\"gzjaoyfhrtxilne\",\"resourceId\":\"kujysvlejuvfq\"}},\"location\":\"rlyxwjkcprbnw\",\"tags\":{\"dnrujqguhmuouqfp\":\"jvtbvpyss\",\"uizga\":\"wzwbnguitn\"},\"id\":\"x\",\"name\":\"fizuckyf\",\"type\":\"hr\"}")
                .toObject(InstanceInner.class);
        Assertions.assertEquals("rlyxwjkcprbnw", model.location());
        Assertions.assertEquals("jvtbvpyss", model.tags().get("dnrujqguhmuouqfp"));
        Assertions.assertEquals("fpsalgbqu", model.iotHubs().get(0).resourceId());
        Assertions.assertEquals(true, model.enableDiagnostics());
        Assertions.assertEquals(AuthenticationType.KEY_BASED, model.diagnosticStorageProperties().authenticationType());
        Assertions.assertEquals("gzjaoyfhrtxilne", model.diagnosticStorageProperties().connectionString());
        Assertions.assertEquals("kujysvlejuvfq", model.diagnosticStorageProperties().resourceId());
    }

    @Test
    public void testSerialize() {
        InstanceInner model =
            new InstanceInner()
                .withLocation("rlyxwjkcprbnw")
                .withTags(mapOf("dnrujqguhmuouqfp", "jvtbvpyss", "uizga", "wzwbnguitn"))
                .withIotHubs(Arrays.asList(new IotHubSettings().withResourceId("fpsalgbqu")))
                .withEnableDiagnostics(true)
                .withDiagnosticStorageProperties(
                    new DiagnosticStorageProperties()
                        .withAuthenticationType(AuthenticationType.KEY_BASED)
                        .withConnectionString("gzjaoyfhrtxilne")
                        .withResourceId("kujysvlejuvfq"));
        model = BinaryData.fromObject(model).toObject(InstanceInner.class);
        Assertions.assertEquals("rlyxwjkcprbnw", model.location());
        Assertions.assertEquals("jvtbvpyss", model.tags().get("dnrujqguhmuouqfp"));
        Assertions.assertEquals("fpsalgbqu", model.iotHubs().get(0).resourceId());
        Assertions.assertEquals(true, model.enableDiagnostics());
        Assertions.assertEquals(AuthenticationType.KEY_BASED, model.diagnosticStorageProperties().authenticationType());
        Assertions.assertEquals("gzjaoyfhrtxilne", model.diagnosticStorageProperties().connectionString());
        Assertions.assertEquals("kujysvlejuvfq", model.diagnosticStorageProperties().resourceId());
    }

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