// 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.IntegrationAccountPartnerInner;
import com.azure.resourcemanager.logic.models.IntegrationAccountPartnerListResult;
import com.azure.resourcemanager.logic.models.PartnerType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IntegrationAccountPartnerListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IntegrationAccountPartnerListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"partnerType\":\"NotSpecified\",\"createdTime\":\"2021-01-20T09:00:38Z\",\"changedTime\":\"2021-10-18T04:08:09Z\",\"metadata\":\"datapevzhfst\"},\"location\":\"txhojujb\",\"tags\":{\"xyfwnylrcool\":\"lmcuvhixb\",\"y\":\"ttpkiwkkbnujrywv\",\"wiithtywub\":\"bfpncurdo\",\"fdntwjchrdgoih\":\"cbihwqk\"},\"id\":\"umwctondz\",\"name\":\"luudfdlwggytsb\",\"type\":\"tov\"},{\"properties\":{\"partnerType\":\"B2B\",\"createdTime\":\"2021-01-15T08:24:44Z\",\"changedTime\":\"2021-01-20T04:42:22Z\",\"metadata\":\"dataqfi\"},\"location\":\"fxqknpirgneptt\",\"tags\":{\"mqnrojlpijnkr\":\"sniffc\",\"zronasxift\":\"frddhcrati\"},\"id\":\"zq\",\"name\":\"zh\",\"type\":\"tw\"},{\"properties\":{\"partnerType\":\"B2B\",\"createdTime\":\"2021-09-16T17:45:36Z\",\"changedTime\":\"2021-06-13T10:36:32Z\",\"metadata\":\"datahonnxkrlgnyhmos\"},\"location\":\"xkk\",\"tags\":{\"pdso\":\"rrghxjbdhqxvcxgf\"},\"id\":\"bshrnsvbuswd\",\"name\":\"z\",\"type\":\"ybycnunvj\"},{\"properties\":{\"partnerType\":\"B2B\",\"createdTime\":\"2021-08-13T04:34:19Z\",\"changedTime\":\"2021-04-02T14:41:37Z\",\"metadata\":\"datanopqgikyzirtx\"},\"location\":\"yuxzejntpsewgi\",\"tags\":{\"mieoxorgguf\":\"qukrydxt\"},\"id\":\"yaomtb\",\"name\":\"hhavgrvkffovjz\",\"type\":\"pjbi\"}],\"nextLink\":\"jmfxumvf\"}")
                .toObject(IntegrationAccountPartnerListResult.class);
        Assertions.assertEquals("txhojujb", model.value().get(0).location());
        Assertions.assertEquals("lmcuvhixb", model.value().get(0).tags().get("xyfwnylrcool"));
        Assertions.assertEquals(PartnerType.NOT_SPECIFIED, model.value().get(0).partnerType());
        Assertions.assertEquals("jmfxumvf", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IntegrationAccountPartnerListResult model =
            new IntegrationAccountPartnerListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IntegrationAccountPartnerInner()
                                .withLocation("txhojujb")
                                .withTags(
                                    mapOf(
                                        "xyfwnylrcool",
                                        "lmcuvhixb",
                                        "y",
                                        "ttpkiwkkbnujrywv",
                                        "wiithtywub",
                                        "bfpncurdo",
                                        "fdntwjchrdgoih",
                                        "cbihwqk"))
                                .withPartnerType(PartnerType.NOT_SPECIFIED)
                                .withMetadata("datapevzhfst"),
                            new IntegrationAccountPartnerInner()
                                .withLocation("fxqknpirgneptt")
                                .withTags(mapOf("mqnrojlpijnkr", "sniffc", "zronasxift", "frddhcrati"))
                                .withPartnerType(PartnerType.B2B)
                                .withMetadata("dataqfi"),
                            new IntegrationAccountPartnerInner()
                                .withLocation("xkk")
                                .withTags(mapOf("pdso", "rrghxjbdhqxvcxgf"))
                                .withPartnerType(PartnerType.B2B)
                                .withMetadata("datahonnxkrlgnyhmos"),
                            new IntegrationAccountPartnerInner()
                                .withLocation("yuxzejntpsewgi")
                                .withTags(mapOf("mieoxorgguf", "qukrydxt"))
                                .withPartnerType(PartnerType.B2B)
                                .withMetadata("datanopqgikyzirtx")))
                .withNextLink("jmfxumvf");
        model = BinaryData.fromObject(model).toObject(IntegrationAccountPartnerListResult.class);
        Assertions.assertEquals("txhojujb", model.value().get(0).location());
        Assertions.assertEquals("lmcuvhixb", model.value().get(0).tags().get("xyfwnylrcool"));
        Assertions.assertEquals(PartnerType.NOT_SPECIFIED, model.value().get(0).partnerType());
        Assertions.assertEquals("jmfxumvf", 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;
    }
}
