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

package com.azure.resourcemanager.logic.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.logic.fluent.models.IntegrationAccountInner;
import com.azure.resourcemanager.logic.models.IntegrationAccountListResult;
import com.azure.resourcemanager.logic.models.IntegrationAccountSku;
import com.azure.resourcemanager.logic.models.IntegrationAccountSkuName;
import com.azure.resourcemanager.logic.models.WorkflowState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IntegrationAccountListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IntegrationAccountListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"state\":\"Suspended\"},\"sku\":{\"name\":\"Basic\"},\"location\":\"hqzonosggbhcoh\",\"tags\":{\"utiiswacf\":\"sjnkal\",\"ewkfvhqcrai\":\"gdkz\"},\"id\":\"vpnpp\",\"name\":\"uflrwd\",\"type\":\"hdlxyjrxsagafcn\"},{\"properties\":{\"state\":\"NotSpecified\"},\"sku\":{\"name\":\"Free\"},\"location\":\"nedgfbc\",\"tags\":{\"pkeqdcvdrhvoo\":\"vq\",\"dopcjwvnh\":\"sotbob\",\"mgxcxrslpm\":\"ld\"},\"id\":\"twuoegrpkhjwni\",\"name\":\"qsluicp\",\"type\":\"ggkzzlvmbmpa\"}],\"nextLink\":\"odfvuefywsbp\"}")
                .toObject(IntegrationAccountListResult.class);
        Assertions.assertEquals("hqzonosggbhcoh", model.value().get(0).location());
        Assertions.assertEquals("sjnkal", model.value().get(0).tags().get("utiiswacf"));
        Assertions.assertEquals(IntegrationAccountSkuName.BASIC, model.value().get(0).sku().name());
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.value().get(0).state());
        Assertions.assertEquals("odfvuefywsbp", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IntegrationAccountListResult model =
            new IntegrationAccountListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IntegrationAccountInner()
                                .withLocation("hqzonosggbhcoh")
                                .withTags(mapOf("utiiswacf", "sjnkal", "ewkfvhqcrai", "gdkz"))
                                .withSku(new IntegrationAccountSku().withName(IntegrationAccountSkuName.BASIC))
                                .withState(WorkflowState.SUSPENDED),
                            new IntegrationAccountInner()
                                .withLocation("nedgfbc")
                                .withTags(mapOf("pkeqdcvdrhvoo", "vq", "dopcjwvnh", "sotbob", "mgxcxrslpm", "ld"))
                                .withSku(new IntegrationAccountSku().withName(IntegrationAccountSkuName.FREE))
                                .withState(WorkflowState.NOT_SPECIFIED)))
                .withNextLink("odfvuefywsbp");
        model = BinaryData.fromObject(model).toObject(IntegrationAccountListResult.class);
        Assertions.assertEquals("hqzonosggbhcoh", model.value().get(0).location());
        Assertions.assertEquals("sjnkal", model.value().get(0).tags().get("utiiswacf"));
        Assertions.assertEquals(IntegrationAccountSkuName.BASIC, model.value().get(0).sku().name());
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.value().get(0).state());
        Assertions.assertEquals("odfvuefywsbp", 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;
    }
}
