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

package com.azure.resourcemanager.appcontainers.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appcontainers.fluent.models.ConnectedEnvironmentInner;
import com.azure.resourcemanager.appcontainers.models.ConnectedEnvironmentCollection;
import com.azure.resourcemanager.appcontainers.models.ExtendedLocation;
import com.azure.resourcemanager.appcontainers.models.ExtendedLocationTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ConnectedEnvironmentCollectionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConnectedEnvironmentCollection model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"extendedLocation\":{\"name\":\"ctehfiqscjey\",\"type\":\"CustomLocation\"},\"properties\":{\"provisioningState\":\"InfrastructureSetupInProgress\",\"deploymentErrors\":\"gqhcjrefovg\",\"defaultDomain\":\"qsl\",\"staticIp\":\"yvxyqjp\",\"daprAIConnectionString\":\"attpngjcrcczsq\"},\"location\":\"vmdajvnysou\",\"tags\":{\"yhltrpmopjmcm\":\"canoaeupf\"},\"id\":\"tuo\",\"name\":\"thfuiuaodsfcpkvx\",\"type\":\"dpuozmyz\"},{\"extendedLocation\":{\"name\":\"gf\",\"type\":\"CustomLocation\"},\"properties\":{\"provisioningState\":\"Waiting\",\"deploymentErrors\":\"iu\",\"defaultDomain\":\"ktwh\",\"staticIp\":\"xw\",\"daprAIConnectionString\":\"wqsmbsur\"},\"location\":\"moryocfsfksym\",\"tags\":{\"o\":\"stkiiuxhqyud\"},\"id\":\"rq\",\"name\":\"b\",\"type\":\"oczvy\"},{\"extendedLocation\":{\"name\":\"rvkdvjsllrm\",\"type\":\"CustomLocation\"},\"properties\":{\"provisioningState\":\"Canceled\",\"deploymentErrors\":\"kpnpulexxbczwtr\",\"defaultDomain\":\"iqzbq\",\"staticIp\":\"sovmyokacspkwl\",\"daprAIConnectionString\":\"dobpxjmflbvvn\"},\"location\":\"kcciwwzjuqkhr\",\"tags\":{\"ghsauuimjmvxied\":\"iwkuofos\",\"byao\":\"ugidyjrr\",\"xc\":\"v\",\"hocohslkev\":\"onpc\"},\"id\":\"eggzfb\",\"name\":\"hfmvfaxkffe\",\"type\":\"ithlvmezyvshxm\"},{\"extendedLocation\":{\"name\":\"bzoggigrx\",\"type\":\"CustomLocation\"},\"properties\":{\"provisioningState\":\"Succeeded\",\"deploymentErrors\":\"xjnspy\",\"defaultDomain\":\"tko\",\"staticIp\":\"kouknvudwtiu\",\"daprAIConnectionString\":\"ldngkpoci\"},\"location\":\"yxoegukgjnp\",\"tags\":{\"zntypmrb\":\"gygev\",\"ydnfyhxdeoejz\":\"izcdrqjsd\"},\"id\":\"cwif\",\"name\":\"jttgzf\",\"type\":\"ishc\"}],\"nextLink\":\"hajdeyeamdpha\"}")
                .toObject(ConnectedEnvironmentCollection.class);
        Assertions.assertEquals("vmdajvnysou", model.value().get(0).location());
        Assertions.assertEquals("canoaeupf", model.value().get(0).tags().get("yhltrpmopjmcm"));
        Assertions.assertEquals("ctehfiqscjey", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("yvxyqjp", model.value().get(0).staticIp());
        Assertions.assertEquals("attpngjcrcczsq", model.value().get(0).daprAIConnectionString());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConnectedEnvironmentCollection model =
            new ConnectedEnvironmentCollection()
                .withValue(
                    Arrays
                        .asList(
                            new ConnectedEnvironmentInner()
                                .withLocation("vmdajvnysou")
                                .withTags(mapOf("yhltrpmopjmcm", "canoaeupf"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("ctehfiqscjey")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withStaticIp("yvxyqjp")
                                .withDaprAIConnectionString("attpngjcrcczsq"),
                            new ConnectedEnvironmentInner()
                                .withLocation("moryocfsfksym")
                                .withTags(mapOf("o", "stkiiuxhqyud"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("gf")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withStaticIp("xw")
                                .withDaprAIConnectionString("wqsmbsur"),
                            new ConnectedEnvironmentInner()
                                .withLocation("kcciwwzjuqkhr")
                                .withTags(
                                    mapOf(
                                        "ghsauuimjmvxied",
                                        "iwkuofos",
                                        "byao",
                                        "ugidyjrr",
                                        "xc",
                                        "v",
                                        "hocohslkev",
                                        "onpc"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("rvkdvjsllrm")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withStaticIp("sovmyokacspkwl")
                                .withDaprAIConnectionString("dobpxjmflbvvn"),
                            new ConnectedEnvironmentInner()
                                .withLocation("yxoegukgjnp")
                                .withTags(mapOf("zntypmrb", "gygev", "ydnfyhxdeoejz", "izcdrqjsd"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("bzoggigrx")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withStaticIp("kouknvudwtiu")
                                .withDaprAIConnectionString("ldngkpoci")));
        model = BinaryData.fromObject(model).toObject(ConnectedEnvironmentCollection.class);
        Assertions.assertEquals("vmdajvnysou", model.value().get(0).location());
        Assertions.assertEquals("canoaeupf", model.value().get(0).tags().get("yhltrpmopjmcm"));
        Assertions.assertEquals("ctehfiqscjey", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals("yvxyqjp", model.value().get(0).staticIp());
        Assertions.assertEquals("attpngjcrcczsq", model.value().get(0).daprAIConnectionString());
    }

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