// 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.ContainerAppInner;
import com.azure.resourcemanager.appcontainers.models.ContainerAppCollection;
import com.azure.resourcemanager.appcontainers.models.ExtendedLocation;
import com.azure.resourcemanager.appcontainers.models.ExtendedLocationTypes;
import com.azure.resourcemanager.appcontainers.models.ManagedServiceIdentity;
import com.azure.resourcemanager.appcontainers.models.ManagedServiceIdentityType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ContainerAppCollectionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ContainerAppCollection model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"extendedLocation\":{\"name\":\"pabgyeps\",\"type\":\"CustomLocation\"},\"identity\":{\"principalId\":\"deac39aa-9334-4790-9a00-fe048007174c\",\"tenantId\":\"b656fa7f-7420-413a-96d5-b297ef5d799b\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"managedBy\":\"ywpmueefjzwfqkq\",\"properties\":{\"provisioningState\":\"Succeeded\",\"managedEnvironmentId\":\"uyonobglaoc\",\"environmentId\":\"tcc\",\"workloadProfileName\":\"yudxytlmoy\",\"latestRevisionName\":\"vwfudwpzntxhd\",\"latestReadyRevisionName\":\"lrqjbhckfr\",\"latestRevisionFqdn\":\"rxsbkyvp\",\"customDomainVerificationId\":\"anuzbpzkafkuw\",\"outboundIpAddresses\":[],\"eventStreamEndpoint\":\"bmehh\"},\"location\":\"yvjusrtslhsp\",\"tags\":{\"elmqk\":\"emaofmxagkvt\",\"hcdhmdual\":\"hahvljuahaq\",\"vfadmws\":\"exq\",\"lf\":\"crgvxpvgom\"},\"id\":\"isgwbnbbeldawkz\",\"name\":\"ali\",\"type\":\"urqhaka\"},{\"extendedLocation\":{\"name\":\"shsfwxosowzxcu\",\"type\":\"CustomLocation\"},\"identity\":{\"principalId\":\"9ca3190e-abc0-4e85-8548-56f3a19fed28\",\"tenantId\":\"63bcc451-5ebd-45a1-8787-75bc7ba93963\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"managedBy\":\"ebwpucwwfvo\",\"properties\":{\"provisioningState\":\"Canceled\",\"managedEnvironmentId\":\"uecivyhz\",\"environmentId\":\"uojgj\",\"workloadProfileName\":\"jueiotwmcdytd\",\"latestRevisionName\":\"it\",\"latestReadyRevisionName\":\"rjaw\",\"latestRevisionFqdn\":\"wgxhn\",\"customDomainVerificationId\":\"kxfbkpycgklwndn\",\"outboundIpAddresses\":[],\"eventStreamEndpoint\":\"whvylw\"},\"location\":\"tdhxujznbmpowuwp\",\"tags\":{\"alupjm\":\"lve\",\"iplrbpbewtghfgb\":\"hfxobbcswsrtj\",\"wxzvlvqhjkb\":\"c\",\"iebwwaloayqcgwrt\":\"gibtnm\"},\"id\":\"j\",\"name\":\"zg\",\"type\":\"yzm\"},{\"extendedLocation\":{\"name\":\"ongmtsa\",\"type\":\"CustomLocation\"},\"identity\":{\"principalId\":\"6656014a-be86-4d71-ad48-13196d61eb24\",\"tenantId\":\"ffaaeb45-4006-4757-beee-682e025e56f7\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"managedBy\":\"srknftguv\",\"properties\":{\"provisioningState\":\"Deleting\",\"managedEnvironmentId\":\"rwmdyvxqtay\",\"environmentId\":\"ww\",\"workloadProfileName\":\"yqbexrmcqibycno\",\"latestRevisionName\":\"knme\",\"latestReadyRevisionName\":\"sgzvahapjyzhpv\",\"latestRevisionFqdn\":\"zcjrvxdjzlmwlx\",\"customDomainVerificationId\":\"ug\",\"outboundIpAddresses\":[],\"eventStreamEndpoint\":\"awjvzunluthnnp\"},\"location\":\"xipeilpjzuaejx\",\"tags\":{\"pwo\":\"tskzbbtdzumveek\",\"fpbsjyofdxl\":\"uh\",\"ttouwaboekqvkel\":\"us\"},\"id\":\"smv\",\"name\":\"xwyjsflhhc\",\"type\":\"aln\"},{\"extendedLocation\":{\"name\":\"isxyawjoyaqcslyj\",\"type\":\"CustomLocation\"},\"identity\":{\"principalId\":\"97813a8e-f400-4824-87f3-35b8b42025f2\",\"tenantId\":\"b6dca7a5-f52d-4d76-8a33-ab158f1d62ad\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"managedBy\":\"znelixhnrztfolh\",\"properties\":{\"provisioningState\":\"Succeeded\",\"managedEnvironmentId\":\"alaulppggdtpnapn\",\"environmentId\":\"ropuhpigv\",\"workloadProfileName\":\"ylgqgitxmedjvcsl\",\"latestRevisionName\":\"qwwncw\",\"latestReadyRevisionName\":\"hxg\",\"latestRevisionFqdn\":\"rmgucnap\",\"customDomainVerificationId\":\"eoellwptfdygp\",\"outboundIpAddresses\":[],\"eventStreamEndpoint\":\"ceopzfqrhhuaopp\"},\"location\":\"qeqxo\",\"tags\":{\"moizpos\":\"ahzxctobgbk\",\"rmfqjhhkxbpvj\":\"mgrcfbu\",\"xjyngudivk\":\"mjh\"},\"id\":\"tswb\",\"name\":\"qzvszjf\",\"type\":\"uvjfdxxive\"}],\"nextLink\":\"t\"}")
                .toObject(ContainerAppCollection.class);
        Assertions.assertEquals("yvjusrtslhsp", model.value().get(0).location());
        Assertions.assertEquals("emaofmxagkvt", model.value().get(0).tags().get("elmqk"));
        Assertions.assertEquals("pabgyeps", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("ywpmueefjzwfqkq", model.value().get(0).managedBy());
        Assertions.assertEquals("uyonobglaoc", model.value().get(0).managedEnvironmentId());
        Assertions.assertEquals("tcc", model.value().get(0).environmentId());
        Assertions.assertEquals("yudxytlmoy", model.value().get(0).workloadProfileName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ContainerAppCollection model =
            new ContainerAppCollection()
                .withValue(
                    Arrays
                        .asList(
                            new ContainerAppInner()
                                .withLocation("yvjusrtslhsp")
                                .withTags(
                                    mapOf(
                                        "elmqk",
                                        "emaofmxagkvt",
                                        "hcdhmdual",
                                        "hahvljuahaq",
                                        "vfadmws",
                                        "exq",
                                        "lf",
                                        "crgvxpvgom"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("pabgyeps")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withManagedBy("ywpmueefjzwfqkq")
                                .withManagedEnvironmentId("uyonobglaoc")
                                .withEnvironmentId("tcc")
                                .withWorkloadProfileName("yudxytlmoy"),
                            new ContainerAppInner()
                                .withLocation("tdhxujznbmpowuwp")
                                .withTags(
                                    mapOf(
                                        "alupjm",
                                        "lve",
                                        "iplrbpbewtghfgb",
                                        "hfxobbcswsrtj",
                                        "wxzvlvqhjkb",
                                        "c",
                                        "iebwwaloayqcgwrt",
                                        "gibtnm"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("shsfwxosowzxcu")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withManagedBy("ebwpucwwfvo")
                                .withManagedEnvironmentId("uecivyhz")
                                .withEnvironmentId("uojgj")
                                .withWorkloadProfileName("jueiotwmcdytd"),
                            new ContainerAppInner()
                                .withLocation("xipeilpjzuaejx")
                                .withTags(mapOf("pwo", "tskzbbtdzumveek", "fpbsjyofdxl", "uh", "ttouwaboekqvkel", "us"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("ongmtsa")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withManagedBy("srknftguv")
                                .withManagedEnvironmentId("rwmdyvxqtay")
                                .withEnvironmentId("ww")
                                .withWorkloadProfileName("yqbexrmcqibycno"),
                            new ContainerAppInner()
                                .withLocation("qeqxo")
                                .withTags(
                                    mapOf("moizpos", "ahzxctobgbk", "rmfqjhhkxbpvj", "mgrcfbu", "xjyngudivk", "mjh"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("isxyawjoyaqcslyj")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withManagedBy("znelixhnrztfolh")
                                .withManagedEnvironmentId("alaulppggdtpnapn")
                                .withEnvironmentId("ropuhpigv")
                                .withWorkloadProfileName("ylgqgitxmedjvcsl")));
        model = BinaryData.fromObject(model).toObject(ContainerAppCollection.class);
        Assertions.assertEquals("yvjusrtslhsp", model.value().get(0).location());
        Assertions.assertEquals("emaofmxagkvt", model.value().get(0).tags().get("elmqk"));
        Assertions.assertEquals("pabgyeps", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals("ywpmueefjzwfqkq", model.value().get(0).managedBy());
        Assertions.assertEquals("uyonobglaoc", model.value().get(0).managedEnvironmentId());
        Assertions.assertEquals("tcc", model.value().get(0).environmentId());
        Assertions.assertEquals("yudxytlmoy", model.value().get(0).workloadProfileName());
    }

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