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

public final class ApiOperationListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApiOperationListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"summary\":\"juj\",\"description\":\"ckpzvcpopmxeln\",\"visibility\":\"ltyjedexxmlfmk\",\"trigger\":\"cazuaw\",\"triggerHint\":\"z\",\"pageable\":true,\"responsesDefinition\":{},\"isWebhook\":false,\"isNotification\":false},\"location\":\"vxcushsphaivmx\",\"tags\":{\"sgzwywakoihknsm\":\"flv\",\"nymzotqyr\":\"blmljh\",\"xmvwfg\":\"uzcbmqq\",\"qnhcvsqltnzoibg\":\"ayxonsupeujl\"},\"id\":\"xgnxfyqonmpqoxwd\",\"name\":\"fdbxiqxeiiqbim\",\"type\":\"tmwwi\"},{\"properties\":{\"summary\":\"hfqpofv\",\"description\":\"cblembnkbwv\",\"visibility\":\"xk\",\"trigger\":\"vqihebwtswbzuwf\",\"triggerHint\":\"urageg\",\"pageable\":true,\"responsesDefinition\":{},\"isWebhook\":false,\"isNotification\":false},\"location\":\"jubggbqigkxkb\",\"tags\":{\"acy\":\"gak\",\"pv\":\"cmjdmspof\",\"iofrzgbzjedmstk\":\"hryl\"},\"id\":\"nlvxbcuii\",\"name\":\"nktwfansnvpdibmi\",\"type\":\"ostbzbkiwb\"},{\"properties\":{\"summary\":\"yophz\",\"description\":\"l\",\"visibility\":\"crpfbcunez\",\"trigger\":\"e\",\"triggerHint\":\"lfwyfwlwxjwetn\",\"pageable\":false,\"responsesDefinition\":{},\"isWebhook\":true,\"isNotification\":false},\"location\":\"ylptrsqqwztcm\",\"tags\":{\"jexfdeqvhp\":\"chcxwaxfewzj\",\"zjrgyww\":\"ylkkshkbffmbm\"},\"id\":\"gjxsnptfu\",\"name\":\"gicgaaoepttaq\",\"type\":\"tdewemxswvruu\"},{\"properties\":{\"summary\":\"jgehkf\",\"description\":\"m\",\"visibility\":\"ixokffqyin\",\"trigger\":\"qepqwhixmon\",\"triggerHint\":\"shiy\",\"pageable\":false,\"responsesDefinition\":{},\"isWebhook\":false,\"isNotification\":false},\"location\":\"cb\",\"tags\":{\"cobiegstmninwjiz\":\"svu\"},\"id\":\"i\",\"name\":\"nghgshej\",\"type\":\"tbxqmuluxlxq\"}],\"nextLink\":\"nersb\"}")
                .toObject(ApiOperationListResult.class);
        Assertions.assertEquals("vxcushsphaivmx", model.value().get(0).location());
        Assertions.assertEquals("flv", model.value().get(0).tags().get("sgzwywakoihknsm"));
        Assertions.assertEquals("juj", model.value().get(0).properties().summary());
        Assertions.assertEquals("ckpzvcpopmxeln", model.value().get(0).properties().description());
        Assertions.assertEquals("ltyjedexxmlfmk", model.value().get(0).properties().visibility());
        Assertions.assertEquals("cazuaw", model.value().get(0).properties().trigger());
        Assertions.assertEquals("z", model.value().get(0).properties().triggerHint());
        Assertions.assertEquals(true, model.value().get(0).properties().pageable());
        Assertions.assertEquals(false, model.value().get(0).properties().isWebhook());
        Assertions.assertEquals(false, model.value().get(0).properties().isNotification());
        Assertions.assertEquals("nersb", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApiOperationListResult model =
            new ApiOperationListResult()
                .withValue(
                    Arrays
                        .asList(
                            new ApiOperationInner()
                                .withLocation("vxcushsphaivmx")
                                .withTags(
                                    mapOf(
                                        "sgzwywakoihknsm",
                                        "flv",
                                        "nymzotqyr",
                                        "blmljh",
                                        "xmvwfg",
                                        "uzcbmqq",
                                        "qnhcvsqltnzoibg",
                                        "ayxonsupeujl"))
                                .withProperties(
                                    new ApiOperationPropertiesDefinition()
                                        .withSummary("juj")
                                        .withDescription("ckpzvcpopmxeln")
                                        .withVisibility("ltyjedexxmlfmk")
                                        .withTrigger("cazuaw")
                                        .withTriggerHint("z")
                                        .withPageable(true)
                                        .withResponsesDefinition(mapOf())
                                        .withIsWebhook(false)
                                        .withIsNotification(false)),
                            new ApiOperationInner()
                                .withLocation("jubggbqigkxkb")
                                .withTags(mapOf("acy", "gak", "pv", "cmjdmspof", "iofrzgbzjedmstk", "hryl"))
                                .withProperties(
                                    new ApiOperationPropertiesDefinition()
                                        .withSummary("hfqpofv")
                                        .withDescription("cblembnkbwv")
                                        .withVisibility("xk")
                                        .withTrigger("vqihebwtswbzuwf")
                                        .withTriggerHint("urageg")
                                        .withPageable(true)
                                        .withResponsesDefinition(mapOf())
                                        .withIsWebhook(false)
                                        .withIsNotification(false)),
                            new ApiOperationInner()
                                .withLocation("ylptrsqqwztcm")
                                .withTags(mapOf("jexfdeqvhp", "chcxwaxfewzj", "zjrgyww", "ylkkshkbffmbm"))
                                .withProperties(
                                    new ApiOperationPropertiesDefinition()
                                        .withSummary("yophz")
                                        .withDescription("l")
                                        .withVisibility("crpfbcunez")
                                        .withTrigger("e")
                                        .withTriggerHint("lfwyfwlwxjwetn")
                                        .withPageable(false)
                                        .withResponsesDefinition(mapOf())
                                        .withIsWebhook(true)
                                        .withIsNotification(false)),
                            new ApiOperationInner()
                                .withLocation("cb")
                                .withTags(mapOf("cobiegstmninwjiz", "svu"))
                                .withProperties(
                                    new ApiOperationPropertiesDefinition()
                                        .withSummary("jgehkf")
                                        .withDescription("m")
                                        .withVisibility("ixokffqyin")
                                        .withTrigger("qepqwhixmon")
                                        .withTriggerHint("shiy")
                                        .withPageable(false)
                                        .withResponsesDefinition(mapOf())
                                        .withIsWebhook(false)
                                        .withIsNotification(false))))
                .withNextLink("nersb");
        model = BinaryData.fromObject(model).toObject(ApiOperationListResult.class);
        Assertions.assertEquals("vxcushsphaivmx", model.value().get(0).location());
        Assertions.assertEquals("flv", model.value().get(0).tags().get("sgzwywakoihknsm"));
        Assertions.assertEquals("juj", model.value().get(0).properties().summary());
        Assertions.assertEquals("ckpzvcpopmxeln", model.value().get(0).properties().description());
        Assertions.assertEquals("ltyjedexxmlfmk", model.value().get(0).properties().visibility());
        Assertions.assertEquals("cazuaw", model.value().get(0).properties().trigger());
        Assertions.assertEquals("z", model.value().get(0).properties().triggerHint());
        Assertions.assertEquals(true, model.value().get(0).properties().pageable());
        Assertions.assertEquals(false, model.value().get(0).properties().isWebhook());
        Assertions.assertEquals(false, model.value().get(0).properties().isNotification());
        Assertions.assertEquals("nersb", 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;
    }
}
