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

package com.azure.resourcemanager.voiceservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.voiceservices.fluent.models.TestLineInner;
import com.azure.resourcemanager.voiceservices.models.TestLineListResult;
import com.azure.resourcemanager.voiceservices.models.TestLinePurpose;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class TestLineListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        TestLineListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Canceled\",\"phoneNumber\":\"gbwjzrnf\",\"purpose\":\"Manual\"},\"location\":\"gispemvtzfkufubl\",\"tags\":{\"v\":\"xqeofjaeqjhqjba\",\"zgcwrw\":\"smjqulngsntnbyb\"},\"id\":\"lxxwrljdouskc\",\"name\":\"vkocrcjdkwtn\",\"type\":\"xbnjbiksq\"},{\"properties\":{\"provisioningState\":\"Succeeded\",\"phoneNumber\":\"sainqpjwnzl\",\"purpose\":\"Manual\"},\"location\":\"mppeebvmgxs\",\"tags\":{\"jczdzevndh\":\"yqduujit\",\"feusnhut\":\"rwpdappdsbdkvwrw\",\"xhocdgeablgphuti\":\"eltmrldhugjzzdat\"},\"id\":\"ndv\",\"name\":\"aozwyiftyhxhu\",\"type\":\"okftyxolniwpwcuk\"}],\"nextLink\":\"kgiawxklryplwck\"}")
                .toObject(TestLineListResult.class);
        Assertions.assertEquals("gispemvtzfkufubl", model.value().get(0).location());
        Assertions.assertEquals("xqeofjaeqjhqjba", model.value().get(0).tags().get("v"));
        Assertions.assertEquals("gbwjzrnf", model.value().get(0).phoneNumber());
        Assertions.assertEquals(TestLinePurpose.MANUAL, model.value().get(0).purpose());
        Assertions.assertEquals("kgiawxklryplwck", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        TestLineListResult model =
            new TestLineListResult()
                .withValue(
                    Arrays
                        .asList(
                            new TestLineInner()
                                .withLocation("gispemvtzfkufubl")
                                .withTags(mapOf("v", "xqeofjaeqjhqjba", "zgcwrw", "smjqulngsntnbyb"))
                                .withPhoneNumber("gbwjzrnf")
                                .withPurpose(TestLinePurpose.MANUAL),
                            new TestLineInner()
                                .withLocation("mppeebvmgxs")
                                .withTags(
                                    mapOf(
                                        "jczdzevndh",
                                        "yqduujit",
                                        "feusnhut",
                                        "rwpdappdsbdkvwrw",
                                        "xhocdgeablgphuti",
                                        "eltmrldhugjzzdat"))
                                .withPhoneNumber("sainqpjwnzl")
                                .withPurpose(TestLinePurpose.MANUAL)))
                .withNextLink("kgiawxklryplwck");
        model = BinaryData.fromObject(model).toObject(TestLineListResult.class);
        Assertions.assertEquals("gispemvtzfkufubl", model.value().get(0).location());
        Assertions.assertEquals("xqeofjaeqjhqjba", model.value().get(0).tags().get("v"));
        Assertions.assertEquals("gbwjzrnf", model.value().get(0).phoneNumber());
        Assertions.assertEquals(TestLinePurpose.MANUAL, model.value().get(0).purpose());
        Assertions.assertEquals("kgiawxklryplwck", 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;
    }
}
