// 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.DeviceSecurityGroupProperties;
import com.azure.resourcemanager.security.models.AllowlistCustomAlertRule;
import com.azure.resourcemanager.security.models.DenylistCustomAlertRule;
import com.azure.resourcemanager.security.models.ThresholdCustomAlertRule;
import com.azure.resourcemanager.security.models.TimeWindowCustomAlertRule;
import java.time.Duration;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class DeviceSecurityGroupPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DeviceSecurityGroupProperties model =
            BinaryData
                .fromString(
                    "{\"thresholdRules\":[{\"ruleType\":\"ThresholdCustomAlertRule\",\"minThreshold\":396023335,\"maxThreshold\":1635783635,\"displayName\":\"dtocj\",\"description\":\"hvpmoue\",\"isEnabled\":false}],\"timeWindowRules\":[{\"ruleType\":\"TimeWindowCustomAlertRule\",\"timeWindowSize\":\"PT62H8M23S\",\"minThreshold\":229644058,\"maxThreshold\":738311617,\"displayName\":\"eojnxqbzvddn\",\"description\":\"ndei\",\"isEnabled\":true},{\"ruleType\":\"TimeWindowCustomAlertRule\",\"timeWindowSize\":\"PT35H10M37S\",\"minThreshold\":206399167,\"maxThreshold\":1604770276,\"displayName\":\"zao\",\"description\":\"uhrhcffcyddgl\",\"isEnabled\":true}],\"allowlistRules\":[{\"ruleType\":\"AllowlistCustomAlertRule\",\"allowlistValues\":[\"qkwpyeicxmqc\",\"wqvhkhixuigdt\",\"pbobjo\"],\"valueType\":\"IpCidr\",\"displayName\":\"w\",\"description\":\"m\",\"isEnabled\":true}],\"denylistRules\":[{\"ruleType\":\"DenylistCustomAlertRule\",\"denylistValues\":[\"ayvvtpgvdf\"],\"valueType\":\"String\",\"displayName\":\"kftutqxlngxlefg\",\"description\":\"nxkrx\",\"isEnabled\":false},{\"ruleType\":\"DenylistCustomAlertRule\",\"denylistValues\":[\"i\"],\"valueType\":\"IpCidr\",\"displayName\":\"zrvqdr\",\"description\":\"hjybigehoqfbo\",\"isEnabled\":false}]}")
                .toObject(DeviceSecurityGroupProperties.class);
        Assertions.assertEquals(false, model.thresholdRules().get(0).isEnabled());
        Assertions.assertEquals(396023335, model.thresholdRules().get(0).minThreshold());
        Assertions.assertEquals(1635783635, model.thresholdRules().get(0).maxThreshold());
        Assertions.assertEquals(true, model.timeWindowRules().get(0).isEnabled());
        Assertions.assertEquals(229644058, model.timeWindowRules().get(0).minThreshold());
        Assertions.assertEquals(738311617, model.timeWindowRules().get(0).maxThreshold());
        Assertions.assertEquals(Duration.parse("PT62H8M23S"), model.timeWindowRules().get(0).timeWindowSize());
        Assertions.assertEquals(true, model.allowlistRules().get(0).isEnabled());
        Assertions.assertEquals("qkwpyeicxmqc", model.allowlistRules().get(0).allowlistValues().get(0));
        Assertions.assertEquals(false, model.denylistRules().get(0).isEnabled());
        Assertions.assertEquals("ayvvtpgvdf", model.denylistRules().get(0).denylistValues().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DeviceSecurityGroupProperties model =
            new DeviceSecurityGroupProperties()
                .withThresholdRules(
                    Arrays
                        .asList(
                            new ThresholdCustomAlertRule()
                                .withIsEnabled(false)
                                .withMinThreshold(396023335)
                                .withMaxThreshold(1635783635)))
                .withTimeWindowRules(
                    Arrays
                        .asList(
                            new TimeWindowCustomAlertRule()
                                .withIsEnabled(true)
                                .withMinThreshold(229644058)
                                .withMaxThreshold(738311617)
                                .withTimeWindowSize(Duration.parse("PT62H8M23S")),
                            new TimeWindowCustomAlertRule()
                                .withIsEnabled(true)
                                .withMinThreshold(206399167)
                                .withMaxThreshold(1604770276)
                                .withTimeWindowSize(Duration.parse("PT35H10M37S"))))
                .withAllowlistRules(
                    Arrays
                        .asList(
                            new AllowlistCustomAlertRule()
                                .withIsEnabled(true)
                                .withAllowlistValues(Arrays.asList("qkwpyeicxmqc", "wqvhkhixuigdt", "pbobjo"))))
                .withDenylistRules(
                    Arrays
                        .asList(
                            new DenylistCustomAlertRule()
                                .withIsEnabled(false)
                                .withDenylistValues(Arrays.asList("ayvvtpgvdf")),
                            new DenylistCustomAlertRule().withIsEnabled(false).withDenylistValues(Arrays.asList("i"))));
        model = BinaryData.fromObject(model).toObject(DeviceSecurityGroupProperties.class);
        Assertions.assertEquals(false, model.thresholdRules().get(0).isEnabled());
        Assertions.assertEquals(396023335, model.thresholdRules().get(0).minThreshold());
        Assertions.assertEquals(1635783635, model.thresholdRules().get(0).maxThreshold());
        Assertions.assertEquals(true, model.timeWindowRules().get(0).isEnabled());
        Assertions.assertEquals(229644058, model.timeWindowRules().get(0).minThreshold());
        Assertions.assertEquals(738311617, model.timeWindowRules().get(0).maxThreshold());
        Assertions.assertEquals(Duration.parse("PT62H8M23S"), model.timeWindowRules().get(0).timeWindowSize());
        Assertions.assertEquals(true, model.allowlistRules().get(0).isEnabled());
        Assertions.assertEquals("qkwpyeicxmqc", model.allowlistRules().get(0).allowlistValues().get(0));
        Assertions.assertEquals(false, model.denylistRules().get(0).isEnabled());
        Assertions.assertEquals("ayvvtpgvdf", model.denylistRules().get(0).denylistValues().get(0));
    }
}
