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

package com.azure.resourcemanager.managednetworkfabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.managednetworkfabric.models.AggregateRoute;
import com.azure.resourcemanager.managednetworkfabric.models.AggregateRouteConfiguration;
import com.azure.resourcemanager.managednetworkfabric.models.ConnectedSubnetRoutePolicy;
import com.azure.resourcemanager.managednetworkfabric.models.L3ExportRoutePolicy;
import com.azure.resourcemanager.managednetworkfabric.models.L3IsolationDomainPatch;
import com.azure.resourcemanager.managednetworkfabric.models.RedistributeConnectedSubnets;
import com.azure.resourcemanager.managednetworkfabric.models.RedistributeStaticRoutes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class L3IsolationDomainPatchTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        L3IsolationDomainPatch model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"redistributeConnectedSubnets\":\"True\",\"redistributeStaticRoutes\":\"False\",\"aggregateRouteConfiguration\":{\"ipv4Routes\":[{\"prefix\":\"kldgrcwfcmfc\"}],\"ipv6Routes\":[{\"prefix\":\"ajqmat\"},{\"prefix\":\"jti\"},{\"prefix\":\"ln\"}]},\"connectedSubnetRoutePolicy\":{\"exportRoutePolicyId\":\"xxgfbbmtlpqagyn\",\"exportRoutePolicy\":{\"exportIpv4RoutePolicyId\":\"rnzcalinc\",\"exportIpv6RoutePolicyId\":\"qxzxaqz\"}},\"annotation\":\"mqimiymqru\"},\"tags\":{\"lanfkgxsya\":\"hfupetasvvoqsbpk\"}}")
                .toObject(L3IsolationDomainPatch.class);
        Assertions.assertEquals("hfupetasvvoqsbpk", model.tags().get("lanfkgxsya"));
        Assertions.assertEquals(RedistributeConnectedSubnets.TRUE, model.redistributeConnectedSubnets());
        Assertions.assertEquals(RedistributeStaticRoutes.FALSE, model.redistributeStaticRoutes());
        Assertions.assertEquals("kldgrcwfcmfc", model.aggregateRouteConfiguration().ipv4Routes().get(0).prefix());
        Assertions.assertEquals("ajqmat", model.aggregateRouteConfiguration().ipv6Routes().get(0).prefix());
        Assertions.assertEquals("xxgfbbmtlpqagyn", model.connectedSubnetRoutePolicy().exportRoutePolicyId());
        Assertions
            .assertEquals(
                "rnzcalinc", model.connectedSubnetRoutePolicy().exportRoutePolicy().exportIpv4RoutePolicyId());
        Assertions
            .assertEquals("qxzxaqz", model.connectedSubnetRoutePolicy().exportRoutePolicy().exportIpv6RoutePolicyId());
        Assertions.assertEquals("mqimiymqru", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        L3IsolationDomainPatch model =
            new L3IsolationDomainPatch()
                .withTags(mapOf("lanfkgxsya", "hfupetasvvoqsbpk"))
                .withRedistributeConnectedSubnets(RedistributeConnectedSubnets.TRUE)
                .withRedistributeStaticRoutes(RedistributeStaticRoutes.FALSE)
                .withAggregateRouteConfiguration(
                    new AggregateRouteConfiguration()
                        .withIpv4Routes(Arrays.asList(new AggregateRoute().withPrefix("kldgrcwfcmfc")))
                        .withIpv6Routes(
                            Arrays
                                .asList(
                                    new AggregateRoute().withPrefix("ajqmat"),
                                    new AggregateRoute().withPrefix("jti"),
                                    new AggregateRoute().withPrefix("ln"))))
                .withConnectedSubnetRoutePolicy(
                    new ConnectedSubnetRoutePolicy()
                        .withExportRoutePolicyId("xxgfbbmtlpqagyn")
                        .withExportRoutePolicy(
                            new L3ExportRoutePolicy()
                                .withExportIpv4RoutePolicyId("rnzcalinc")
                                .withExportIpv6RoutePolicyId("qxzxaqz")))
                .withAnnotation("mqimiymqru");
        model = BinaryData.fromObject(model).toObject(L3IsolationDomainPatch.class);
        Assertions.assertEquals("hfupetasvvoqsbpk", model.tags().get("lanfkgxsya"));
        Assertions.assertEquals(RedistributeConnectedSubnets.TRUE, model.redistributeConnectedSubnets());
        Assertions.assertEquals(RedistributeStaticRoutes.FALSE, model.redistributeStaticRoutes());
        Assertions.assertEquals("kldgrcwfcmfc", model.aggregateRouteConfiguration().ipv4Routes().get(0).prefix());
        Assertions.assertEquals("ajqmat", model.aggregateRouteConfiguration().ipv6Routes().get(0).prefix());
        Assertions.assertEquals("xxgfbbmtlpqagyn", model.connectedSubnetRoutePolicy().exportRoutePolicyId());
        Assertions
            .assertEquals(
                "rnzcalinc", model.connectedSubnetRoutePolicy().exportRoutePolicy().exportIpv4RoutePolicyId());
        Assertions
            .assertEquals("qxzxaqz", model.connectedSubnetRoutePolicy().exportRoutePolicy().exportIpv6RoutePolicyId());
        Assertions.assertEquals("mqimiymqru", model.annotation());
    }

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