// 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.fluent.models.AlertsSuppressionRuleProperties;
import com.azure.resourcemanager.security.models.RuleState;
import com.azure.resourcemanager.security.models.ScopeElement;
import com.azure.resourcemanager.security.models.SuppressionAlertsScope;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AlertsSuppressionRulePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AlertsSuppressionRuleProperties model =
            BinaryData
                .fromString(
                    "{\"alertType\":\"lqubkwdlen\",\"lastModifiedUtc\":\"2021-02-18T06:07:47Z\",\"expirationDateUtc\":\"2021-03-05T15:56:58Z\",\"reason\":\"ujbazpjuohminyfl\",\"state\":\"Enabled\",\"comment\":\"wmd\",\"suppressionAlertsScope\":{\"allOf\":[{\"field\":\"klvxwmyg\",\"\":{}},{\"field\":\"gpqch\",\"\":{}}]}}")
                .toObject(AlertsSuppressionRuleProperties.class);
        Assertions.assertEquals("lqubkwdlen", model.alertType());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-05T15:56:58Z"), model.expirationDateUtc());
        Assertions.assertEquals("ujbazpjuohminyfl", model.reason());
        Assertions.assertEquals(RuleState.ENABLED, model.state());
        Assertions.assertEquals("wmd", model.comment());
        Assertions.assertEquals("klvxwmyg", model.suppressionAlertsScope().allOf().get(0).field());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AlertsSuppressionRuleProperties model =
            new AlertsSuppressionRuleProperties()
                .withAlertType("lqubkwdlen")
                .withExpirationDateUtc(OffsetDateTime.parse("2021-03-05T15:56:58Z"))
                .withReason("ujbazpjuohminyfl")
                .withState(RuleState.ENABLED)
                .withComment("wmd")
                .withSuppressionAlertsScope(
                    new SuppressionAlertsScope()
                        .withAllOf(
                            Arrays
                                .asList(
                                    new ScopeElement().withField("klvxwmyg").withAdditionalProperties(mapOf()),
                                    new ScopeElement().withField("gpqch").withAdditionalProperties(mapOf()))));
        model = BinaryData.fromObject(model).toObject(AlertsSuppressionRuleProperties.class);
        Assertions.assertEquals("lqubkwdlen", model.alertType());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-05T15:56:58Z"), model.expirationDateUtc());
        Assertions.assertEquals("ujbazpjuohminyfl", model.reason());
        Assertions.assertEquals(RuleState.ENABLED, model.state());
        Assertions.assertEquals("wmd", model.comment());
        Assertions.assertEquals("klvxwmyg", model.suppressionAlertsScope().allOf().get(0).field());
    }

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