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

package com.azure.resourcemanager.mysqlflexibleserver.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mysqlflexibleserver.fluent.models.OperationInner;
import com.azure.resourcemanager.mysqlflexibleserver.models.OperationDisplay;
import com.azure.resourcemanager.mysqlflexibleserver.models.OperationListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class OperationListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        OperationListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"name\":\"izcdrqjsd\",\"display\":{\"provider\":\"nfyhx\",\"resource\":\"oejzi\",\"operation\":\"ifsjttgzfbishcb\",\"description\":\"ajdeyeamdphaga\"},\"origin\":\"buxwgip\",\"properties\":{\"nkixzbinj\":\"datanowkgshw\",\"tmryw\":\"datapu\"}},{\"name\":\"zoqftiyqzrnkcqvy\",\"display\":{\"provider\":\"hzls\",\"resource\":\"ohoqqnwvlryav\",\"operation\":\"heun\",\"description\":\"qhgyxzkonocukok\"},\"origin\":\"axuconuq\",\"properties\":{\"rmjmwvvjektc\":\"datakbeype\",\"frzpwvlqdqgb\":\"datasenhwlrs\"}},{\"name\":\"ylihkaetckt\",\"display\":{\"provider\":\"ivfsnk\",\"resource\":\"uctqhjfbe\",\"operation\":\"jcxerfuwu\",\"description\":\"txfvjrbirph\"},\"origin\":\"pcyvahfnljkyqx\",\"properties\":{\"jljyoxgv\":\"dataujqgidok\",\"szzhbijhtxfvgxbf\":\"dataltbgsncghkj\",\"ec\":\"datamxnehmp\",\"gr\":\"datagodebfqkkrbmpu\"}},{\"name\":\"flz\",\"display\":{\"provider\":\"xzpuzycisp\",\"resource\":\"zahmgkbrpyydhibn\",\"operation\":\"qkpikadrgvtqagnb\",\"description\":\"nhijggmebfsi\"},\"origin\":\"butr\",\"properties\":{\"zmhjrunmp\":\"datana\",\"nkxmyskpbhenbtk\":\"datattdbhrbnl\"}}],\"nextLink\":\"ywn\"}")
                .toObject(OperationListResult.class);
        Assertions.assertEquals("izcdrqjsd", model.value().get(0).name());
        Assertions.assertEquals("nfyhx", model.value().get(0).display().provider());
        Assertions.assertEquals("oejzi", model.value().get(0).display().resource());
        Assertions.assertEquals("ifsjttgzfbishcb", model.value().get(0).display().operation());
        Assertions.assertEquals("ajdeyeamdphaga", model.value().get(0).display().description());
        Assertions.assertEquals("buxwgip", model.value().get(0).origin());
        Assertions.assertEquals("ywn", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        OperationListResult model =
            new OperationListResult()
                .withValue(
                    Arrays
                        .asList(
                            new OperationInner()
                                .withName("izcdrqjsd")
                                .withDisplay(
                                    new OperationDisplay()
                                        .withProvider("nfyhx")
                                        .withResource("oejzi")
                                        .withOperation("ifsjttgzfbishcb")
                                        .withDescription("ajdeyeamdphaga"))
                                .withOrigin("buxwgip")
                                .withProperties(mapOf("nkixzbinj", "datanowkgshw", "tmryw", "datapu")),
                            new OperationInner()
                                .withName("zoqftiyqzrnkcqvy")
                                .withDisplay(
                                    new OperationDisplay()
                                        .withProvider("hzls")
                                        .withResource("ohoqqnwvlryav")
                                        .withOperation("heun")
                                        .withDescription("qhgyxzkonocukok"))
                                .withOrigin("axuconuq")
                                .withProperties(mapOf("rmjmwvvjektc", "datakbeype", "frzpwvlqdqgb", "datasenhwlrs")),
                            new OperationInner()
                                .withName("ylihkaetckt")
                                .withDisplay(
                                    new OperationDisplay()
                                        .withProvider("ivfsnk")
                                        .withResource("uctqhjfbe")
                                        .withOperation("jcxerfuwu")
                                        .withDescription("txfvjrbirph"))
                                .withOrigin("pcyvahfnljkyqx")
                                .withProperties(
                                    mapOf(
                                        "jljyoxgv",
                                        "dataujqgidok",
                                        "szzhbijhtxfvgxbf",
                                        "dataltbgsncghkj",
                                        "ec",
                                        "datamxnehmp",
                                        "gr",
                                        "datagodebfqkkrbmpu")),
                            new OperationInner()
                                .withName("flz")
                                .withDisplay(
                                    new OperationDisplay()
                                        .withProvider("xzpuzycisp")
                                        .withResource("zahmgkbrpyydhibn")
                                        .withOperation("qkpikadrgvtqagnb")
                                        .withDescription("nhijggmebfsi"))
                                .withOrigin("butr")
                                .withProperties(mapOf("zmhjrunmp", "datana", "nkxmyskpbhenbtk", "datattdbhrbnl"))))
                .withNextLink("ywn");
        model = BinaryData.fromObject(model).toObject(OperationListResult.class);
        Assertions.assertEquals("izcdrqjsd", model.value().get(0).name());
        Assertions.assertEquals("nfyhx", model.value().get(0).display().provider());
        Assertions.assertEquals("oejzi", model.value().get(0).display().resource());
        Assertions.assertEquals("ifsjttgzfbishcb", model.value().get(0).display().operation());
        Assertions.assertEquals("ajdeyeamdphaga", model.value().get(0).display().description());
        Assertions.assertEquals("buxwgip", model.value().get(0).origin());
        Assertions.assertEquals("ywn", 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;
    }
}
