// 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.models.SwaggerCustomDynamicTree;
import com.azure.resourcemanager.logic.models.SwaggerCustomDynamicTreeCommand;
import com.azure.resourcemanager.logic.models.SwaggerCustomDynamicTreeParameter;
import com.azure.resourcemanager.logic.models.SwaggerCustomDynamicTreeSettings;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SwaggerCustomDynamicTreeTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SwaggerCustomDynamicTree model =
            BinaryData
                .fromString(
                    "{\"settings\":{\"CanSelectParentNodes\":true,\"CanSelectLeafNodes\":false},\"open\":{\"operationId\":\"jhhhqxu\",\"itemsPath\":\"vcacoyv\",\"itemValuePath\":\"bsizus\",\"itemTitlePath\":\"zlbscmnlziji\",\"itemFullTitlePath\":\"ehgmvflnwyv\",\"itemIsParent\":\"xrerlniylylyf\",\"selectableFilter\":\"zutgqztwhghmupg\",\"parameters\":{\"xzu\":{\"selectedItemValuePath\":\"cdxa\",\"value\":\"datau\",\"parameterReference\":\"tabenbbk\",\"required\":false},\"luclvdjjuk\":{\"selectedItemValuePath\":\"feddwwnlza\",\"value\":\"dataxud\",\"parameterReference\":\"hgookrtalvnbwgpb\",\"required\":true},\"emchgavsczuej\":{\"selectedItemValuePath\":\"dnqodx\",\"value\":\"datah\",\"parameterReference\":\"qfaqnvzoqg\",\"required\":false},\"xydkxrx\":{\"selectedItemValuePath\":\"xptlghwzho\",\"value\":\"datawjjstliuhqa\",\"parameterReference\":\"oaiancznvodrrs\",\"required\":true}}},\"browse\":{\"operationId\":\"xiwkgfbql\",\"itemsPath\":\"qkhychocok\",\"itemValuePath\":\"ehurqlr\",\"itemTitlePath\":\"fawey\",\"itemFullTitlePath\":\"kphyjdxrav\",\"itemIsParent\":\"qdbrxmrgc\",\"selectableFilter\":\"apx\",\"parameters\":{\"ycblevpmcl\":{\"selectedItemValuePath\":\"jjk\",\"value\":\"datajbuscg\",\"parameterReference\":\"u\",\"required\":true}}}}")
                .toObject(SwaggerCustomDynamicTree.class);
        Assertions.assertEquals(true, model.settings().canSelectParentNodes());
        Assertions.assertEquals(false, model.settings().canSelectLeafNodes());
        Assertions.assertEquals("jhhhqxu", model.open().operationId());
        Assertions.assertEquals("vcacoyv", model.open().itemsPath());
        Assertions.assertEquals("bsizus", model.open().itemValuePath());
        Assertions.assertEquals("zlbscmnlziji", model.open().itemTitlePath());
        Assertions.assertEquals("ehgmvflnwyv", model.open().itemFullTitlePath());
        Assertions.assertEquals("xrerlniylylyf", model.open().itemIsParent());
        Assertions.assertEquals("zutgqztwhghmupg", model.open().selectableFilter());
        Assertions.assertEquals("cdxa", model.open().parameters().get("xzu").selectedItemValuePath());
        Assertions.assertEquals("tabenbbk", model.open().parameters().get("xzu").parameterReference());
        Assertions.assertEquals(false, model.open().parameters().get("xzu").required());
        Assertions.assertEquals("xiwkgfbql", model.browse().operationId());
        Assertions.assertEquals("qkhychocok", model.browse().itemsPath());
        Assertions.assertEquals("ehurqlr", model.browse().itemValuePath());
        Assertions.assertEquals("fawey", model.browse().itemTitlePath());
        Assertions.assertEquals("kphyjdxrav", model.browse().itemFullTitlePath());
        Assertions.assertEquals("qdbrxmrgc", model.browse().itemIsParent());
        Assertions.assertEquals("apx", model.browse().selectableFilter());
        Assertions.assertEquals("jjk", model.browse().parameters().get("ycblevpmcl").selectedItemValuePath());
        Assertions.assertEquals("u", model.browse().parameters().get("ycblevpmcl").parameterReference());
        Assertions.assertEquals(true, model.browse().parameters().get("ycblevpmcl").required());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SwaggerCustomDynamicTree model =
            new SwaggerCustomDynamicTree()
                .withSettings(
                    new SwaggerCustomDynamicTreeSettings().withCanSelectParentNodes(true).withCanSelectLeafNodes(false))
                .withOpen(
                    new SwaggerCustomDynamicTreeCommand()
                        .withOperationId("jhhhqxu")
                        .withItemsPath("vcacoyv")
                        .withItemValuePath("bsizus")
                        .withItemTitlePath("zlbscmnlziji")
                        .withItemFullTitlePath("ehgmvflnwyv")
                        .withItemIsParent("xrerlniylylyf")
                        .withSelectableFilter("zutgqztwhghmupg")
                        .withParameters(
                            mapOf(
                                "xzu",
                                new SwaggerCustomDynamicTreeParameter()
                                    .withSelectedItemValuePath("cdxa")
                                    .withValue("datau")
                                    .withParameterReference("tabenbbk")
                                    .withRequired(false),
                                "luclvdjjuk",
                                new SwaggerCustomDynamicTreeParameter()
                                    .withSelectedItemValuePath("feddwwnlza")
                                    .withValue("dataxud")
                                    .withParameterReference("hgookrtalvnbwgpb")
                                    .withRequired(true),
                                "emchgavsczuej",
                                new SwaggerCustomDynamicTreeParameter()
                                    .withSelectedItemValuePath("dnqodx")
                                    .withValue("datah")
                                    .withParameterReference("qfaqnvzoqg")
                                    .withRequired(false),
                                "xydkxrx",
                                new SwaggerCustomDynamicTreeParameter()
                                    .withSelectedItemValuePath("xptlghwzho")
                                    .withValue("datawjjstliuhqa")
                                    .withParameterReference("oaiancznvodrrs")
                                    .withRequired(true))))
                .withBrowse(
                    new SwaggerCustomDynamicTreeCommand()
                        .withOperationId("xiwkgfbql")
                        .withItemsPath("qkhychocok")
                        .withItemValuePath("ehurqlr")
                        .withItemTitlePath("fawey")
                        .withItemFullTitlePath("kphyjdxrav")
                        .withItemIsParent("qdbrxmrgc")
                        .withSelectableFilter("apx")
                        .withParameters(
                            mapOf(
                                "ycblevpmcl",
                                new SwaggerCustomDynamicTreeParameter()
                                    .withSelectedItemValuePath("jjk")
                                    .withValue("datajbuscg")
                                    .withParameterReference("u")
                                    .withRequired(true))));
        model = BinaryData.fromObject(model).toObject(SwaggerCustomDynamicTree.class);
        Assertions.assertEquals(true, model.settings().canSelectParentNodes());
        Assertions.assertEquals(false, model.settings().canSelectLeafNodes());
        Assertions.assertEquals("jhhhqxu", model.open().operationId());
        Assertions.assertEquals("vcacoyv", model.open().itemsPath());
        Assertions.assertEquals("bsizus", model.open().itemValuePath());
        Assertions.assertEquals("zlbscmnlziji", model.open().itemTitlePath());
        Assertions.assertEquals("ehgmvflnwyv", model.open().itemFullTitlePath());
        Assertions.assertEquals("xrerlniylylyf", model.open().itemIsParent());
        Assertions.assertEquals("zutgqztwhghmupg", model.open().selectableFilter());
        Assertions.assertEquals("cdxa", model.open().parameters().get("xzu").selectedItemValuePath());
        Assertions.assertEquals("tabenbbk", model.open().parameters().get("xzu").parameterReference());
        Assertions.assertEquals(false, model.open().parameters().get("xzu").required());
        Assertions.assertEquals("xiwkgfbql", model.browse().operationId());
        Assertions.assertEquals("qkhychocok", model.browse().itemsPath());
        Assertions.assertEquals("ehurqlr", model.browse().itemValuePath());
        Assertions.assertEquals("fawey", model.browse().itemTitlePath());
        Assertions.assertEquals("kphyjdxrav", model.browse().itemFullTitlePath());
        Assertions.assertEquals("qdbrxmrgc", model.browse().itemIsParent());
        Assertions.assertEquals("apx", model.browse().selectableFilter());
        Assertions.assertEquals("jjk", model.browse().parameters().get("ycblevpmcl").selectedItemValuePath());
        Assertions.assertEquals("u", model.browse().parameters().get("ycblevpmcl").parameterReference());
        Assertions.assertEquals(true, model.browse().parameters().get("ycblevpmcl").required());
    }

    @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;
    }
}
