// 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.fluent.models.RoutePolicyInner;
import com.azure.resourcemanager.managednetworkfabric.models.RoutePolicyStatementProperties;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class RoutePolicyInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RoutePolicyInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"statements\":[{\"sequenceNumber\":738730611020453628,\"annotation\":\"odawopqhewjptmcg\"},{\"sequenceNumber\":7587339093272860703,\"annotation\":\"t\"}],\"provisioningState\":\"Canceled\",\"annotation\":\"dlat\"},\"location\":\"mzlbiojlvfhrb\",\"tags\":{\"prprsnmokay\":\"eqvcwwyyurmoch\",\"pcpil\":\"ejnhlbkpb\",\"hol\":\"hahzvechndbnwi\",\"efqsfapaqtferrqw\":\"wjwiuub\"},\"id\":\"x\",\"name\":\"kmfx\",\"type\":\"pjwogqqno\"}")
                .toObject(RoutePolicyInner.class);
        Assertions.assertEquals("mzlbiojlvfhrb", model.location());
        Assertions.assertEquals("eqvcwwyyurmoch", model.tags().get("prprsnmokay"));
        Assertions.assertEquals("odawopqhewjptmcg", model.statements().get(0).annotation());
        Assertions.assertEquals(738730611020453628L, model.statements().get(0).sequenceNumber());
        Assertions.assertEquals("dlat", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RoutePolicyInner model =
            new RoutePolicyInner()
                .withLocation("mzlbiojlvfhrb")
                .withTags(
                    mapOf(
                        "prprsnmokay",
                        "eqvcwwyyurmoch",
                        "pcpil",
                        "ejnhlbkpb",
                        "hol",
                        "hahzvechndbnwi",
                        "efqsfapaqtferrqw",
                        "wjwiuub"))
                .withStatements(
                    Arrays
                        .asList(
                            new RoutePolicyStatementProperties()
                                .withAnnotation("odawopqhewjptmcg")
                                .withSequenceNumber(738730611020453628L),
                            new RoutePolicyStatementProperties()
                                .withAnnotation("t")
                                .withSequenceNumber(7587339093272860703L)))
                .withAnnotation("dlat");
        model = BinaryData.fromObject(model).toObject(RoutePolicyInner.class);
        Assertions.assertEquals("mzlbiojlvfhrb", model.location());
        Assertions.assertEquals("eqvcwwyyurmoch", model.tags().get("prprsnmokay"));
        Assertions.assertEquals("odawopqhewjptmcg", model.statements().get(0).annotation());
        Assertions.assertEquals(738730611020453628L, model.statements().get(0).sequenceNumber());
        Assertions.assertEquals("dlat", 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;
    }
}
