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

package com.azure.resourcemanager.baremetalinfrastructure.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.baremetalinfrastructure.fluent.models.AzureBareMetalInstanceInner;
import com.azure.resourcemanager.baremetalinfrastructure.models.AzureBareMetalInstancesListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureBareMetalInstancesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureBareMetalInstancesListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"azureBareMetalInstanceId\":\"xpyb\",\"powerState\":\"stopped\",\"proximityPlacementGroup\":\"hmtzopbsphrup\",\"hwRevision\":\"gsybbejhp\",\"partnerNodeId\":\"ycm\",\"provisioningState\":\"Migrating\"},\"location\":\"bhdxbm\",\"tags\":{\"zhwlrxy\":\"oqjzehtbmufpowno\"},\"id\":\"qsoqijgkd\",\"name\":\"bpazlobcufpdzn\",\"type\":\"btcqq\"},{\"properties\":{\"azureBareMetalInstanceId\":\"gnufoooj\",\"powerState\":\"restarting\",\"proximityPlacementGroup\":\"sqe\",\"hwRevision\":\"agdfmglzlh\",\"partnerNodeId\":\"rifkwm\",\"provisioningState\":\"Updating\"},\"location\":\"siznto\",\"tags\":{\"uajpsquc\":\"a\"},\"id\":\"poyfdkfogkn\",\"name\":\"gjofjd\",\"type\":\"eqsrdeupewnwreit\"},{\"properties\":{\"azureBareMetalInstanceId\":\"arhmofcqhsmy\",\"powerState\":\"stopped\",\"proximityPlacementGroup\":\"tmlxhekuksjtx\",\"hwRevision\":\"cdm\",\"partnerNodeId\":\"rcryuanzwuxzdxta\",\"provisioningState\":\"Failed\"},\"location\":\"m\",\"tags\":{\"u\":\"pmrqobm\"},\"id\":\"knryrtihfxtij\",\"name\":\"pzvgnwzsymglzufc\",\"type\":\"zk\"}],\"nextLink\":\"dbihanufhfcbj\"}")
                .toObject(AzureBareMetalInstancesListResult.class);
        Assertions.assertEquals("bhdxbm", model.value().get(0).location());
        Assertions.assertEquals("oqjzehtbmufpowno", model.value().get(0).tags().get("zhwlrxy"));
        Assertions.assertEquals("ycm", model.value().get(0).partnerNodeId());
        Assertions.assertEquals("dbihanufhfcbj", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureBareMetalInstancesListResult model =
            new AzureBareMetalInstancesListResult()
                .withValue(
                    Arrays
                        .asList(
                            new AzureBareMetalInstanceInner()
                                .withLocation("bhdxbm")
                                .withTags(mapOf("zhwlrxy", "oqjzehtbmufpowno"))
                                .withPartnerNodeId("ycm"),
                            new AzureBareMetalInstanceInner()
                                .withLocation("siznto")
                                .withTags(mapOf("uajpsquc", "a"))
                                .withPartnerNodeId("rifkwm"),
                            new AzureBareMetalInstanceInner()
                                .withLocation("m")
                                .withTags(mapOf("u", "pmrqobm"))
                                .withPartnerNodeId("rcryuanzwuxzdxta")))
                .withNextLink("dbihanufhfcbj");
        model = BinaryData.fromObject(model).toObject(AzureBareMetalInstancesListResult.class);
        Assertions.assertEquals("bhdxbm", model.value().get(0).location());
        Assertions.assertEquals("oqjzehtbmufpowno", model.value().get(0).tags().get("zhwlrxy"));
        Assertions.assertEquals("ycm", model.value().get(0).partnerNodeId());
        Assertions.assertEquals("dbihanufhfcbj", model.nextLink());
    }

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