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

package com.azure.resourcemanager.mediaservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mediaservices.fluent.models.MediaServiceInner;
import com.azure.resourcemanager.mediaservices.models.MediaServiceCollection;
import com.azure.resourcemanager.mediaservices.models.MediaServiceIdentity;
import com.azure.resourcemanager.mediaservices.models.MinimumTlsVersion;
import com.azure.resourcemanager.mediaservices.models.PublicNetworkAccess;
import com.azure.resourcemanager.mediaservices.models.StorageAuthentication;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class MediaServiceCollectionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MediaServiceCollection model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"mediaServiceId\":\"bc8caf84-beca-4093-94b1-76a9b6759cc5\",\"storageAccounts\":[],\"storageAuthentication\":\"ManagedIdentity\",\"publicNetworkAccess\":\"Enabled\",\"provisioningState\":\"Succeeded\",\"privateEndpointConnections\":[],\"minimumTlsVersion\":\"Tls10\"},\"identity\":{\"type\":\"fqpte\",\"principalId\":\"fd1fb765-6619-41e2-baf6-40d06da56fae\",\"tenantId\":\"8657e53a-6d11-445c-9ecb-26919b4cc50d\",\"userAssignedIdentities\":{}},\"location\":\"vypyqrimzinpv\",\"tags\":{\"nohjt\":\"dkirsoodqxhcr\",\"soifiyipjxsqw\":\"kwh\",\"bznorcjxvsnby\":\"gr\"},\"id\":\"qabnmoc\",\"name\":\"cyshurzafbljjgp\",\"type\":\"toqcjmklja\"}],\"@odata.nextLink\":\"qidtqajzyu\"}")
                .toObject(MediaServiceCollection.class);
        Assertions.assertEquals("vypyqrimzinpv", model.value().get(0).location());
        Assertions.assertEquals("dkirsoodqxhcr", model.value().get(0).tags().get("nohjt"));
        Assertions.assertEquals("fqpte", model.value().get(0).identity().type());
        Assertions.assertEquals(StorageAuthentication.MANAGED_IDENTITY, model.value().get(0).storageAuthentication());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(MinimumTlsVersion.TLS10, model.value().get(0).minimumTlsVersion());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MediaServiceCollection model =
            new MediaServiceCollection()
                .withValue(
                    Arrays
                        .asList(
                            new MediaServiceInner()
                                .withLocation("vypyqrimzinpv")
                                .withTags(
                                    mapOf("nohjt", "dkirsoodqxhcr", "soifiyipjxsqw", "kwh", "bznorcjxvsnby", "gr"))
                                .withIdentity(
                                    new MediaServiceIdentity().withType("fqpte").withUserAssignedIdentities(mapOf()))
                                .withStorageAccounts(Arrays.asList())
                                .withStorageAuthentication(StorageAuthentication.MANAGED_IDENTITY)
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withMinimumTlsVersion(MinimumTlsVersion.TLS10)));
        model = BinaryData.fromObject(model).toObject(MediaServiceCollection.class);
        Assertions.assertEquals("vypyqrimzinpv", model.value().get(0).location());
        Assertions.assertEquals("dkirsoodqxhcr", model.value().get(0).tags().get("nohjt"));
        Assertions.assertEquals("fqpte", model.value().get(0).identity().type());
        Assertions.assertEquals(StorageAuthentication.MANAGED_IDENTITY, model.value().get(0).storageAuthentication());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(MinimumTlsVersion.TLS10, model.value().get(0).minimumTlsVersion());
    }

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