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

package com.azure.resourcemanager.networkfunction.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.networkfunction.fluent.models.CollectorPolicyInner;
import com.azure.resourcemanager.networkfunction.models.EmissionPoliciesPropertiesFormat;
import com.azure.resourcemanager.networkfunction.models.EmissionType;
import com.azure.resourcemanager.networkfunction.models.IngestionPolicyPropertiesFormat;
import com.azure.resourcemanager.networkfunction.models.IngestionType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class CollectorPolicyInnerTests {
    @Test
    public void testDeserialize() {
        CollectorPolicyInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"ingestionPolicy\":{\"ingestionType\":\"IPFIX\",\"ingestionSources\":[]},\"emissionPolicies\":[{\"emissionType\":\"IPFIX\",\"emissionDestinations\":[]},{\"emissionType\":\"IPFIX\",\"emissionDestinations\":[]}],\"provisioningState\":\"Updating\"},\"etag\":\"wckbasyypnd\",\"location\":\"sgcbac\",\"tags\":{\"nqgoulzndli\":\"jkot\"},\"id\":\"wyqkgfgibm\",\"name\":\"dgak\",\"type\":\"qsrxybzqqed\"}")
                .toObject(CollectorPolicyInner.class);
        Assertions.assertEquals("sgcbac", model.location());
        Assertions.assertEquals("jkot", model.tags().get("nqgoulzndli"));
        Assertions.assertEquals(IngestionType.IPFIX, model.ingestionPolicy().ingestionType());
        Assertions.assertEquals(EmissionType.IPFIX, model.emissionPolicies().get(0).emissionType());
    }

    @Test
    public void testSerialize() {
        CollectorPolicyInner model =
            new CollectorPolicyInner()
                .withLocation("sgcbac")
                .withTags(mapOf("nqgoulzndli", "jkot"))
                .withIngestionPolicy(
                    new IngestionPolicyPropertiesFormat()
                        .withIngestionType(IngestionType.IPFIX)
                        .withIngestionSources(Arrays.asList()))
                .withEmissionPolicies(
                    Arrays
                        .asList(
                            new EmissionPoliciesPropertiesFormat()
                                .withEmissionType(EmissionType.IPFIX)
                                .withEmissionDestinations(Arrays.asList()),
                            new EmissionPoliciesPropertiesFormat()
                                .withEmissionType(EmissionType.IPFIX)
                                .withEmissionDestinations(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(CollectorPolicyInner.class);
        Assertions.assertEquals("sgcbac", model.location());
        Assertions.assertEquals("jkot", model.tags().get("nqgoulzndli"));
        Assertions.assertEquals(IngestionType.IPFIX, model.ingestionPolicy().ingestionType());
        Assertions.assertEquals(EmissionType.IPFIX, model.emissionPolicies().get(0).emissionType());
    }

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