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

package com.azure.resourcemanager.peering.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.peering.fluent.models.PeeringInner;
import com.azure.resourcemanager.peering.models.DirectPeeringType;
import com.azure.resourcemanager.peering.models.Family;
import com.azure.resourcemanager.peering.models.Kind;
import com.azure.resourcemanager.peering.models.PeeringPropertiesDirect;
import com.azure.resourcemanager.peering.models.PeeringPropertiesExchange;
import com.azure.resourcemanager.peering.models.PeeringSku;
import com.azure.resourcemanager.peering.models.Size;
import com.azure.resourcemanager.peering.models.Tier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PeeringInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PeeringInner model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"ahbc\",\"tier\":\"Premium\",\"family\":\"Exchange\",\"size\":\"Free\"},\"kind\":\"Direct\",\"properties\":{\"direct\":{\"connections\":[],\"useForPeeringService\":true,\"directPeeringType\":\"Ix\"},\"exchange\":{\"connections\":[]},\"peeringLocation\":\"bzjhcrzevdp\",\"provisioningState\":\"Updating\"},\"location\":\"aolthqtrg\",\"tags\":{\"rwzoxxjtfelluwf\":\"pfzfsinzgvfc\"},\"id\":\"it\",\"name\":\"np\",\"type\":\"qfpjk\"}")
                .toObject(PeeringInner.class);
        Assertions.assertEquals("ahbc", model.sku().name());
        Assertions.assertEquals(Tier.PREMIUM, model.sku().tier());
        Assertions.assertEquals(Family.EXCHANGE, model.sku().family());
        Assertions.assertEquals(Size.FREE, model.sku().size());
        Assertions.assertEquals(Kind.DIRECT, model.kind());
        Assertions.assertEquals("aolthqtrg", model.location());
        Assertions.assertEquals("pfzfsinzgvfc", model.tags().get("rwzoxxjtfelluwf"));
        Assertions.assertEquals(DirectPeeringType.IX, model.direct().directPeeringType());
        Assertions.assertEquals("bzjhcrzevdp", model.peeringLocation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PeeringInner model =
            new PeeringInner()
                .withSku(
                    new PeeringSku()
                        .withName("ahbc")
                        .withTier(Tier.PREMIUM)
                        .withFamily(Family.EXCHANGE)
                        .withSize(Size.FREE))
                .withKind(Kind.DIRECT)
                .withLocation("aolthqtrg")
                .withTags(mapOf("rwzoxxjtfelluwf", "pfzfsinzgvfc"))
                .withDirect(
                    new PeeringPropertiesDirect()
                        .withConnections(Arrays.asList())
                        .withDirectPeeringType(DirectPeeringType.IX))
                .withExchange(new PeeringPropertiesExchange().withConnections(Arrays.asList()))
                .withPeeringLocation("bzjhcrzevdp");
        model = BinaryData.fromObject(model).toObject(PeeringInner.class);
        Assertions.assertEquals("ahbc", model.sku().name());
        Assertions.assertEquals(Tier.PREMIUM, model.sku().tier());
        Assertions.assertEquals(Family.EXCHANGE, model.sku().family());
        Assertions.assertEquals(Size.FREE, model.sku().size());
        Assertions.assertEquals(Kind.DIRECT, model.kind());
        Assertions.assertEquals("aolthqtrg", model.location());
        Assertions.assertEquals("pfzfsinzgvfc", model.tags().get("rwzoxxjtfelluwf"));
        Assertions.assertEquals(DirectPeeringType.IX, model.direct().directPeeringType());
        Assertions.assertEquals("bzjhcrzevdp", model.peeringLocation());
    }

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