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

package com.azure.resourcemanager.security.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.security.models.RecommendationConfigStatus;
import com.azure.resourcemanager.security.models.RecommendationConfigurationProperties;
import com.azure.resourcemanager.security.models.RecommendationType;
import com.azure.resourcemanager.security.models.UpdateIotSecuritySolutionData;
import com.azure.resourcemanager.security.models.UserDefinedResourcesProperties;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class UpdateIotSecuritySolutionDataTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        UpdateIotSecuritySolutionData model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"userDefinedResources\":{\"query\":\"cxgod\",\"querySubscriptions\":[\"fqkkr\",\"mpukgriw\"]},\"recommendationsConfiguration\":[{\"recommendationType\":\"IoT_PermissiveOutputFirewallRules\",\"name\":\"bxzpuzycisp\",\"status\":\"Enabled\"},{\"recommendationType\":\"IoT_VulnerableTLSCipherSuite\",\"name\":\"hmgkbrpyy\",\"status\":\"Enabled\"},{\"recommendationType\":\"IoT_OpenPorts\",\"name\":\"nuqqkpikadrgvt\",\"status\":\"Disabled\"},{\"recommendationType\":\"IoT_EdgeLoggingOptions\",\"name\":\"buynhijggm\",\"status\":\"Disabled\"}]},\"tags\":{\"zmhjrunmp\":\"iarbutrcvpna\",\"nkxmyskpbhenbtk\":\"ttdbhrbnl\",\"yxczfclh\":\"xywnytnrsynlqidy\"}}")
                .toObject(UpdateIotSecuritySolutionData.class);
        Assertions.assertEquals("iarbutrcvpna", model.tags().get("zmhjrunmp"));
        Assertions.assertEquals("cxgod", model.userDefinedResources().query());
        Assertions.assertEquals("fqkkr", model.userDefinedResources().querySubscriptions().get(0));
        Assertions
            .assertEquals(
                RecommendationType.IO_T_PERMISSIVE_OUTPUT_FIREWALL_RULES,
                model.recommendationsConfiguration().get(0).recommendationType());
        Assertions
            .assertEquals(RecommendationConfigStatus.ENABLED, model.recommendationsConfiguration().get(0).status());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        UpdateIotSecuritySolutionData model =
            new UpdateIotSecuritySolutionData()
                .withTags(
                    mapOf("zmhjrunmp", "iarbutrcvpna", "nkxmyskpbhenbtk", "ttdbhrbnl", "yxczfclh", "xywnytnrsynlqidy"))
                .withUserDefinedResources(
                    new UserDefinedResourcesProperties()
                        .withQuery("cxgod")
                        .withQuerySubscriptions(Arrays.asList("fqkkr", "mpukgriw")))
                .withRecommendationsConfiguration(
                    Arrays
                        .asList(
                            new RecommendationConfigurationProperties()
                                .withRecommendationType(RecommendationType.IO_T_PERMISSIVE_OUTPUT_FIREWALL_RULES)
                                .withStatus(RecommendationConfigStatus.ENABLED),
                            new RecommendationConfigurationProperties()
                                .withRecommendationType(RecommendationType.IO_T_VULNERABLE_TLSCIPHER_SUITE)
                                .withStatus(RecommendationConfigStatus.ENABLED),
                            new RecommendationConfigurationProperties()
                                .withRecommendationType(RecommendationType.IO_T_OPEN_PORTS)
                                .withStatus(RecommendationConfigStatus.DISABLED),
                            new RecommendationConfigurationProperties()
                                .withRecommendationType(RecommendationType.IO_T_EDGE_LOGGING_OPTIONS)
                                .withStatus(RecommendationConfigStatus.DISABLED)));
        model = BinaryData.fromObject(model).toObject(UpdateIotSecuritySolutionData.class);
        Assertions.assertEquals("iarbutrcvpna", model.tags().get("zmhjrunmp"));
        Assertions.assertEquals("cxgod", model.userDefinedResources().query());
        Assertions.assertEquals("fqkkr", model.userDefinedResources().querySubscriptions().get(0));
        Assertions
            .assertEquals(
                RecommendationType.IO_T_PERMISSIVE_OUTPUT_FIREWALL_RULES,
                model.recommendationsConfiguration().get(0).recommendationType());
        Assertions
            .assertEquals(RecommendationConfigStatus.ENABLED, model.recommendationsConfiguration().get(0).status());
    }

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