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

package com.azure.resourcemanager.maintenance.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.maintenance.fluent.models.MaintenanceConfigurationInner;
import com.azure.resourcemanager.maintenance.models.ListMaintenanceConfigurationsResult;
import com.azure.resourcemanager.maintenance.models.MaintenanceScope;
import com.azure.resourcemanager.maintenance.models.Visibility;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ListMaintenanceConfigurationsResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ListMaintenanceConfigurationsResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"location\":\"quvgjxpybczme\",\"tags\":{\"bb\":\"zopbsphrupidgs\",\"sx\":\"jhphoyc\",\"tbmufpo\":\"obhdxbmtqioqjze\",\"hwlrx\":\"noi\"},\"properties\":{\"namespace\":\"soqijg\",\"extensionProperties\":{},\"maintenanceScope\":\"SQLDB\",\"visibility\":\"Public\"},\"id\":\"obcu\",\"name\":\"pdznrbtcqqjnqgl\",\"type\":\"qgn\"},{\"location\":\"ooojywifsqe\",\"tags\":{\"glzlhjxrifkwmrv\":\"gdf\",\"psqucmpoyf\":\"tsizntocipaoua\",\"knygjofjddeq\":\"kfo\"},\"properties\":{\"namespace\":\"eupewnwreitjz\",\"extensionProperties\":{},\"maintenanceScope\":\"SQLManagedInstance\",\"visibility\":\"Custom\"},\"id\":\"mofcq\",\"name\":\"smy\",\"type\":\"rkdtmlxh\"},{\"location\":\"uksjtxukcdmp\",\"tags\":{\"lhmwhfpmrqobm\":\"ryuanzwuxzdxtay\",\"knryrtihfxtij\":\"u\"},\"properties\":{\"namespace\":\"vg\",\"extensionProperties\":{},\"maintenanceScope\":\"SQLManagedInstance\",\"visibility\":\"Custom\"},\"id\":\"zufcyzkohdbi\",\"name\":\"anufhfcbjysag\",\"type\":\"th\"}]}")
                .toObject(ListMaintenanceConfigurationsResult.class);
        Assertions.assertEquals("quvgjxpybczme", model.value().get(0).location());
        Assertions.assertEquals("zopbsphrupidgs", model.value().get(0).tags().get("bb"));
        Assertions.assertEquals("soqijg", model.value().get(0).namespace());
        Assertions.assertEquals(MaintenanceScope.SQLDB, model.value().get(0).maintenanceScope());
        Assertions.assertEquals(Visibility.PUBLIC, model.value().get(0).visibility());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ListMaintenanceConfigurationsResult model =
            new ListMaintenanceConfigurationsResult()
                .withValue(
                    Arrays
                        .asList(
                            new MaintenanceConfigurationInner()
                                .withLocation("quvgjxpybczme")
                                .withTags(
                                    mapOf(
                                        "bb",
                                        "zopbsphrupidgs",
                                        "sx",
                                        "jhphoyc",
                                        "tbmufpo",
                                        "obhdxbmtqioqjze",
                                        "hwlrx",
                                        "noi"))
                                .withNamespace("soqijg")
                                .withExtensionProperties(mapOf())
                                .withMaintenanceScope(MaintenanceScope.SQLDB)
                                .withVisibility(Visibility.PUBLIC),
                            new MaintenanceConfigurationInner()
                                .withLocation("ooojywifsqe")
                                .withTags(
                                    mapOf(
                                        "glzlhjxrifkwmrv",
                                        "gdf",
                                        "psqucmpoyf",
                                        "tsizntocipaoua",
                                        "knygjofjddeq",
                                        "kfo"))
                                .withNamespace("eupewnwreitjz")
                                .withExtensionProperties(mapOf())
                                .withMaintenanceScope(MaintenanceScope.SQLMANAGED_INSTANCE)
                                .withVisibility(Visibility.CUSTOM),
                            new MaintenanceConfigurationInner()
                                .withLocation("uksjtxukcdmp")
                                .withTags(mapOf("lhmwhfpmrqobm", "ryuanzwuxzdxtay", "knryrtihfxtij", "u"))
                                .withNamespace("vg")
                                .withExtensionProperties(mapOf())
                                .withMaintenanceScope(MaintenanceScope.SQLMANAGED_INSTANCE)
                                .withVisibility(Visibility.CUSTOM)));
        model = BinaryData.fromObject(model).toObject(ListMaintenanceConfigurationsResult.class);
        Assertions.assertEquals("quvgjxpybczme", model.value().get(0).location());
        Assertions.assertEquals("zopbsphrupidgs", model.value().get(0).tags().get("bb"));
        Assertions.assertEquals("soqijg", model.value().get(0).namespace());
        Assertions.assertEquals(MaintenanceScope.SQLDB, model.value().get(0).maintenanceScope());
        Assertions.assertEquals(Visibility.PUBLIC, model.value().get(0).visibility());
    }

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