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

package com.azure.resourcemanager.frontdoor.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.frontdoor.models.ActionType;
import com.azure.resourcemanager.frontdoor.models.CustomRule;
import com.azure.resourcemanager.frontdoor.models.CustomRuleEnabledState;
import com.azure.resourcemanager.frontdoor.models.CustomRuleList;
import com.azure.resourcemanager.frontdoor.models.RuleType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class CustomRuleListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CustomRuleList model =
            BinaryData
                .fromString(
                    "{\"rules\":[{\"name\":\"cnyejhkryhtnapcz\",\"priority\":48641393,\"enabledState\":\"Disabled\",\"ruleType\":\"MatchRule\",\"rateLimitDurationInMinutes\":782174040,\"rateLimitThreshold\":186394728,\"matchConditions\":[],\"action\":\"Log\"}]}")
                .toObject(CustomRuleList.class);
        Assertions.assertEquals("cnyejhkryhtnapcz", model.rules().get(0).name());
        Assertions.assertEquals(48641393, model.rules().get(0).priority());
        Assertions.assertEquals(CustomRuleEnabledState.DISABLED, model.rules().get(0).enabledState());
        Assertions.assertEquals(RuleType.MATCH_RULE, model.rules().get(0).ruleType());
        Assertions.assertEquals(782174040, model.rules().get(0).rateLimitDurationInMinutes());
        Assertions.assertEquals(186394728, model.rules().get(0).rateLimitThreshold());
        Assertions.assertEquals(ActionType.LOG, model.rules().get(0).action());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CustomRuleList model =
            new CustomRuleList()
                .withRules(
                    Arrays
                        .asList(
                            new CustomRule()
                                .withName("cnyejhkryhtnapcz")
                                .withPriority(48641393)
                                .withEnabledState(CustomRuleEnabledState.DISABLED)
                                .withRuleType(RuleType.MATCH_RULE)
                                .withRateLimitDurationInMinutes(782174040)
                                .withRateLimitThreshold(186394728)
                                .withMatchConditions(Arrays.asList())
                                .withAction(ActionType.LOG)));
        model = BinaryData.fromObject(model).toObject(CustomRuleList.class);
        Assertions.assertEquals("cnyejhkryhtnapcz", model.rules().get(0).name());
        Assertions.assertEquals(48641393, model.rules().get(0).priority());
        Assertions.assertEquals(CustomRuleEnabledState.DISABLED, model.rules().get(0).enabledState());
        Assertions.assertEquals(RuleType.MATCH_RULE, model.rules().get(0).ruleType());
        Assertions.assertEquals(782174040, model.rules().get(0).rateLimitDurationInMinutes());
        Assertions.assertEquals(186394728, model.rules().get(0).rateLimitThreshold());
        Assertions.assertEquals(ActionType.LOG, model.rules().get(0).action());
    }
}
