// 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.StreamingEndpointInner;
import com.azure.resourcemanager.mediaservices.models.ArmStreamingEndpointCurrentSku;
import com.azure.resourcemanager.mediaservices.models.CrossSiteAccessPolicies;
import com.azure.resourcemanager.mediaservices.models.StreamingEndpointAccessControl;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class StreamingEndpointInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        StreamingEndpointInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"description\":\"ilqu\",\"scaleUnits\":1776914172,\"availabilitySetName\":\"dxtqmieoxo\",\"accessControl\":{},\"maxCacheAge\":6726931432797365258,\"customHostNames\":[\"mtbghh\",\"vgrvkffo\",\"jzhpjbibgjmfx\",\"mv\"],\"hostName\":\"luyovwxnbkfezzx\",\"cdnEnabled\":true,\"cdnProvider\":\"wzdgirujbzbo\",\"cdnProfile\":\"zzbtdcqvpniyujvi\",\"provisioningState\":\"wdsh\",\"resourceState\":\"Running\",\"crossSiteAccessPolicies\":{\"clientAccessPolicy\":\"bgye\",\"crossDomainPolicy\":\"ymsgaojfmwnc\"},\"freeTrialEndTime\":\"2021-04-29T14:25:51Z\",\"created\":\"2021-07-03T18:59:53Z\",\"lastModified\":\"2021-11-17T23:30:45Z\"},\"sku\":{\"name\":\"ymoxoftpipiwyczu\",\"capacity\":148157875},\"location\":\"cpqjlihhyu\",\"tags\":{\"wdgzxulucv\":\"kasdvlm\",\"urisjnhnytxifqj\":\"amrsreuzv\",\"esutrgjupauutpw\":\"gxmrhublwp\",\"jqgwzp\":\"qhih\"},\"id\":\"fqntcyp\",\"name\":\"xjvfoimwksl\",\"type\":\"rcizjxvyd\"}")
                .toObject(StreamingEndpointInner.class);
        Assertions.assertEquals("cpqjlihhyu", model.location());
        Assertions.assertEquals("kasdvlm", model.tags().get("wdgzxulucv"));
        Assertions.assertEquals(148157875, model.sku().capacity());
        Assertions.assertEquals("ilqu", model.description());
        Assertions.assertEquals(1776914172, model.scaleUnits());
        Assertions.assertEquals("dxtqmieoxo", model.availabilitySetName());
        Assertions.assertEquals(6726931432797365258L, model.maxCacheAge());
        Assertions.assertEquals("mtbghh", model.customHostNames().get(0));
        Assertions.assertEquals(true, model.cdnEnabled());
        Assertions.assertEquals("wzdgirujbzbo", model.cdnProvider());
        Assertions.assertEquals("zzbtdcqvpniyujvi", model.cdnProfile());
        Assertions.assertEquals("bgye", model.crossSiteAccessPolicies().clientAccessPolicy());
        Assertions.assertEquals("ymsgaojfmwnc", model.crossSiteAccessPolicies().crossDomainPolicy());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        StreamingEndpointInner model =
            new StreamingEndpointInner()
                .withLocation("cpqjlihhyu")
                .withTags(
                    mapOf(
                        "wdgzxulucv",
                        "kasdvlm",
                        "urisjnhnytxifqj",
                        "amrsreuzv",
                        "esutrgjupauutpw",
                        "gxmrhublwp",
                        "jqgwzp",
                        "qhih"))
                .withSku(new ArmStreamingEndpointCurrentSku().withCapacity(148157875))
                .withDescription("ilqu")
                .withScaleUnits(1776914172)
                .withAvailabilitySetName("dxtqmieoxo")
                .withAccessControl(new StreamingEndpointAccessControl())
                .withMaxCacheAge(6726931432797365258L)
                .withCustomHostNames(Arrays.asList("mtbghh", "vgrvkffo", "jzhpjbibgjmfx", "mv"))
                .withCdnEnabled(true)
                .withCdnProvider("wzdgirujbzbo")
                .withCdnProfile("zzbtdcqvpniyujvi")
                .withCrossSiteAccessPolicies(
                    new CrossSiteAccessPolicies().withClientAccessPolicy("bgye").withCrossDomainPolicy("ymsgaojfmwnc"));
        model = BinaryData.fromObject(model).toObject(StreamingEndpointInner.class);
        Assertions.assertEquals("cpqjlihhyu", model.location());
        Assertions.assertEquals("kasdvlm", model.tags().get("wdgzxulucv"));
        Assertions.assertEquals(148157875, model.sku().capacity());
        Assertions.assertEquals("ilqu", model.description());
        Assertions.assertEquals(1776914172, model.scaleUnits());
        Assertions.assertEquals("dxtqmieoxo", model.availabilitySetName());
        Assertions.assertEquals(6726931432797365258L, model.maxCacheAge());
        Assertions.assertEquals("mtbghh", model.customHostNames().get(0));
        Assertions.assertEquals(true, model.cdnEnabled());
        Assertions.assertEquals("wzdgirujbzbo", model.cdnProvider());
        Assertions.assertEquals("zzbtdcqvpniyujvi", model.cdnProfile());
        Assertions.assertEquals("bgye", model.crossSiteAccessPolicies().clientAccessPolicy());
        Assertions.assertEquals("ymsgaojfmwnc", model.crossSiteAccessPolicies().crossDomainPolicy());
    }

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