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

package com.azure.resourcemanager.synapse.generated;

import com.azure.core.util.BinaryData;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.synapse.fluent.models.SelfHostedIntegrationRuntimeNodeInner;
import com.azure.resourcemanager.synapse.models.LinkedIntegrationRuntime;
import com.azure.resourcemanager.synapse.models.SelfHostedIntegrationRuntimeStatus;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SelfHostedIntegrationRuntimeStatusTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SelfHostedIntegrationRuntimeStatus model =
            BinaryData
                .fromString(
                    "{\"type\":\"SelfHosted\",\"typeProperties\":{\"createTime\":\"2020-12-26T02:01:59Z\",\"taskQueueId\":\"nokzwjjz\",\"nodeCommunicationChannelEncryptionMode\":\"tixldzyyfytpqs\",\"internalChannelEncryption\":\"SslEncrypted\",\"version\":\"m\",\"nodes\":[{\"nodeName\":\"vyqlkjuvsmbmslzo\",\"machineName\":\"vwzdbpqvyb\",\"hostServiceUri\":\"gvmxnok\",\"status\":\"Offline\",\"capabilities\":{},\"versionStatus\":\"bse\",\"version\":\"vcuartrhun\",\"registerTime\":\"2021-10-23T09:44:51Z\",\"lastConnectTime\":\"2021-03-25T16:48:43Z\",\"expiryTime\":\"2021-01-17T22:26:54Z\",\"lastStartTime\":\"2021-09-25T18:28:14Z\",\"lastStopTime\":\"2021-08-08T22:57:09Z\",\"lastUpdateResult\":\"Fail\",\"lastStartUpdateTime\":\"2021-05-27T06:07:42Z\",\"lastEndUpdateTime\":\"2021-10-29T14:16:23Z\",\"isActiveDispatcher\":false,\"concurrentJobsLimit\":924088824,\"maxConcurrentJobs\":1327984375,\"\":{}},{\"nodeName\":\"wagltbxoeeonqlnf\",\"machineName\":\"y\",\"hostServiceUri\":\"vqdbpbhfck\",\"status\":\"Offline\",\"capabilities\":{},\"versionStatus\":\"rcssbzhddubbnq\",\"version\":\"lhkalehpavawugi\",\"registerTime\":\"2021-02-25T01:40:45Z\",\"lastConnectTime\":\"2021-04-01T19:27:08Z\",\"expiryTime\":\"2021-07-26T21:58:24Z\",\"lastStartTime\":\"2021-07-01T06:50:20Z\",\"lastStopTime\":\"2021-09-05T10:18:10Z\",\"lastUpdateResult\":\"Fail\",\"lastStartUpdateTime\":\"2021-05-05T10:06:38Z\",\"lastEndUpdateTime\":\"2021-08-05T18:56:25Z\",\"isActiveDispatcher\":false,\"concurrentJobsLimit\":495911185,\"maxConcurrentJobs\":1621846817,\"\":{}},{\"nodeName\":\"pnbonhpcz\",\"machineName\":\"mktp\",\"hostServiceUri\":\"xqcsehch\",\"status\":\"InitializeFailed\",\"capabilities\":{},\"versionStatus\":\"pqumqyjgydzulo\",\"version\":\"aeuzanh\",\"registerTime\":\"2021-11-19T22:08:29Z\",\"lastConnectTime\":\"2021-09-25T14:16:25Z\",\"expiryTime\":\"2021-09-07T18:47:04Z\",\"lastStartTime\":\"2020-12-23T17:30:48Z\",\"lastStopTime\":\"2021-07-07T19:48:07Z\",\"lastUpdateResult\":\"Fail\",\"lastStartUpdateTime\":\"2021-08-08T10:34:07Z\",\"lastEndUpdateTime\":\"2021-07-05T02:00:42Z\",\"isActiveDispatcher\":true,\"concurrentJobsLimit\":1809951616,\"maxConcurrentJobs\":1731697979,\"\":{}}],\"scheduledUpdateDate\":\"2020-12-23T03:00:17Z\",\"updateDelayOffset\":\"jufwbeqrkuorhtss\",\"localTimeZoneOffset\":\"qnmdvhazcvjy\",\"capabilities\":{\"txtd\":\"swbqerzwxi\",\"ktg\":\"ukvlb\",\"bewreswmowegmmut\":\"styoua\"},\"serviceUrls\":[\"eyguq\"],\"autoUpdate\":\"On\",\"versionStatus\":\"ii\",\"links\":[{\"name\":\"xlzdesygrijwa\",\"subscriptionId\":\"fanraybfu\",\"dataFactoryName\":\"frojsydgr\",\"dataFactoryLocation\":\"dkygywezski\",\"createTime\":\"2021-01-02T19:13:56Z\"},{\"name\":\"ygzmxieqvdsmak\",\"subscriptionId\":\"xq\",\"dataFactoryName\":\"hyhxa\",\"dataFactoryLocation\":\"bx\",\"createTime\":\"2021-08-24T02:30:22Z\"}],\"pushedVersion\":\"jpodtbl\",\"latestVersion\":\"kkwjdjodq\",\"autoUpdateETA\":\"2021-01-07T22:22:02Z\",\"serviceRegion\":\"ncn\",\"newerVersions\":[\"ehllizhceum\",\"qodkadppyibngql\",\"d\"],\"osType\":30824840,\"targetFramework\":1164247130},\"dataFactoryName\":\"yd\",\"state\":\"Stopped\",\"\":{\"nuyemlowuo\":\"dataadswz\",\"blgmokzkltrfowtd\":\"datahlxlnwyrmou\"}}")
                .toObject(SelfHostedIntegrationRuntimeStatus.class);
        Assertions.assertEquals("ncn", model.serviceRegion());
        Assertions.assertEquals("ehllizhceum", model.newerVersions().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SelfHostedIntegrationRuntimeStatus model =
            new SelfHostedIntegrationRuntimeStatus()
                .withNodes(
                    Arrays
                        .asList(
                            new SelfHostedIntegrationRuntimeNodeInner()
                                .withAdditionalProperties(
                                    mapOf(
                                        "nodeName",
                                        "vyqlkjuvsmbmslzo",
                                        "lastStartUpdateTime",
                                        "2021-05-27T06:07:42Z",
                                        "lastConnectTime",
                                        "2021-03-25T16:48:43Z",
                                        "capabilities",
                                        JacksonAdapter
                                            .createDefaultSerializerAdapter()
                                            .deserialize("{}", Object.class, SerializerEncoding.JSON),
                                        "hostServiceUri",
                                        "gvmxnok",
                                        "registerTime",
                                        "2021-10-23T09:44:51Z",
                                        "maxConcurrentJobs",
                                        1327984375,
                                        "lastStopTime",
                                        "2021-08-08T22:57:09Z",
                                        "version",
                                        "vcuartrhun",
                                        "machineName",
                                        "vwzdbpqvyb",
                                        "versionStatus",
                                        "bse",
                                        "concurrentJobsLimit",
                                        924088824,
                                        "lastEndUpdateTime",
                                        "2021-10-29T14:16:23Z",
                                        "expiryTime",
                                        "2021-01-17T22:26:54Z",
                                        "lastStartTime",
                                        "2021-09-25T18:28:14Z",
                                        "lastUpdateResult",
                                        "Fail",
                                        "isActiveDispatcher",
                                        false,
                                        "status",
                                        "Offline")),
                            new SelfHostedIntegrationRuntimeNodeInner()
                                .withAdditionalProperties(
                                    mapOf(
                                        "nodeName",
                                        "wagltbxoeeonqlnf",
                                        "lastStartUpdateTime",
                                        "2021-05-05T10:06:38Z",
                                        "lastConnectTime",
                                        "2021-04-01T19:27:08Z",
                                        "capabilities",
                                        JacksonAdapter
                                            .createDefaultSerializerAdapter()
                                            .deserialize("{}", Object.class, SerializerEncoding.JSON),
                                        "hostServiceUri",
                                        "vqdbpbhfck",
                                        "registerTime",
                                        "2021-02-25T01:40:45Z",
                                        "maxConcurrentJobs",
                                        1621846817,
                                        "lastStopTime",
                                        "2021-09-05T10:18:10Z",
                                        "version",
                                        "lhkalehpavawugi",
                                        "machineName",
                                        "y",
                                        "versionStatus",
                                        "rcssbzhddubbnq",
                                        "concurrentJobsLimit",
                                        495911185,
                                        "lastEndUpdateTime",
                                        "2021-08-05T18:56:25Z",
                                        "expiryTime",
                                        "2021-07-26T21:58:24Z",
                                        "lastStartTime",
                                        "2021-07-01T06:50:20Z",
                                        "lastUpdateResult",
                                        "Fail",
                                        "isActiveDispatcher",
                                        false,
                                        "status",
                                        "Offline")),
                            new SelfHostedIntegrationRuntimeNodeInner()
                                .withAdditionalProperties(
                                    mapOf(
                                        "nodeName",
                                        "pnbonhpcz",
                                        "lastStartUpdateTime",
                                        "2021-08-08T10:34:07Z",
                                        "lastConnectTime",
                                        "2021-09-25T14:16:25Z",
                                        "capabilities",
                                        JacksonAdapter
                                            .createDefaultSerializerAdapter()
                                            .deserialize("{}", Object.class, SerializerEncoding.JSON),
                                        "hostServiceUri",
                                        "xqcsehch",
                                        "registerTime",
                                        "2021-11-19T22:08:29Z",
                                        "maxConcurrentJobs",
                                        1731697979,
                                        "lastStopTime",
                                        "2021-07-07T19:48:07Z",
                                        "version",
                                        "aeuzanh",
                                        "machineName",
                                        "mktp",
                                        "versionStatus",
                                        "pqumqyjgydzulo",
                                        "concurrentJobsLimit",
                                        1809951616,
                                        "lastEndUpdateTime",
                                        "2021-07-05T02:00:42Z",
                                        "expiryTime",
                                        "2021-09-07T18:47:04Z",
                                        "lastStartTime",
                                        "2020-12-23T17:30:48Z",
                                        "lastUpdateResult",
                                        "Fail",
                                        "isActiveDispatcher",
                                        true,
                                        "status",
                                        "InitializeFailed"))))
                .withLinks(Arrays.asList(new LinkedIntegrationRuntime(), new LinkedIntegrationRuntime()))
                .withServiceRegion("ncn")
                .withNewerVersions(Arrays.asList("ehllizhceum", "qodkadppyibngql", "d"));
        model = BinaryData.fromObject(model).toObject(SelfHostedIntegrationRuntimeStatus.class);
        Assertions.assertEquals("ncn", model.serviceRegion());
        Assertions.assertEquals("ehllizhceum", model.newerVersions().get(0));
    }

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