// 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.fluent.models.FrontDoorInner;
import com.azure.resourcemanager.frontdoor.fluent.models.FrontendEndpointInner;
import com.azure.resourcemanager.frontdoor.models.BackendPool;
import com.azure.resourcemanager.frontdoor.models.BackendPoolsSettings;
import com.azure.resourcemanager.frontdoor.models.EnforceCertificateNameCheckEnabledState;
import com.azure.resourcemanager.frontdoor.models.FrontDoorEnabledState;
import com.azure.resourcemanager.frontdoor.models.HealthProbeSettingsModel;
import com.azure.resourcemanager.frontdoor.models.LoadBalancingSettingsModel;
import com.azure.resourcemanager.frontdoor.models.RoutingRule;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class FrontDoorInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        FrontDoorInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"resourceState\":\"Enabled\",\"provisioningState\":\"ayvvtpgvdf\",\"cname\":\"otkftutqxlngx\",\"frontdoorId\":\"fgugnxkrxdqmid\",\"rulesEngines\":[{\"id\":\"rvqdra\",\"name\":\"hjybigehoqfbo\",\"type\":\"skanyk\"},{\"id\":\"lcuiywgqywgndr\",\"name\":\"ynhz\",\"type\":\"pphrcgynco\"}],\"extendedProperties\":{\"fsxlzevgbmqjqa\":\"cfvmmco\",\"pmivkwlzu\":\"c\"},\"friendlyName\":\"c\",\"routingRules\":[{\"name\":\"bacfionlebxetq\",\"type\":\"zxdpnqbqqw\",\"id\":\"jfeallnwsub\"},{\"name\":\"jampmngnzscxaqw\",\"type\":\"chcbonqvpkvlrxnj\",\"id\":\"seiphe\"},{\"name\":\"okeyyienj\",\"type\":\"lwtgrhpdj\",\"id\":\"umasxazjpq\"},{\"name\":\"ualhbxxhejj\",\"type\":\"v\",\"id\":\"dgwdslfhot\"}],\"loadBalancingSettings\":[{\"name\":\"pwlbjnpg\",\"type\":\"ftadehxnltyfs\",\"id\":\"pusuesn\"},{\"name\":\"ej\",\"type\":\"vorxzdmohct\",\"id\":\"vudwx\"},{\"name\":\"nvowgujju\",\"type\":\"dkcglhsl\",\"id\":\"jdyggdtji\"}],\"healthProbeSettings\":[{\"name\":\"ofqweykhmenevfye\",\"type\":\"whybcib\",\"id\":\"vdcsitynn\"}],\"backendPools\":[{\"name\":\"ctehfiqscjey\",\"type\":\"hezrkgq\",\"id\":\"jrefovgmkqsle\"},{\"name\":\"xyqj\",\"type\":\"cattpngjcrcczsq\",\"id\":\"hvmdajvnysounq\"},{\"name\":\"noae\",\"type\":\"fhyhltrpmopjmcma\",\"id\":\"okth\"},{\"name\":\"uaodsfcpk\",\"type\":\"odpuozmyzydag\",\"id\":\"axbezyiuo\"}],\"frontendEndpoints\":[{\"name\":\"rdxwzywqsm\",\"type\":\"ureximoryocfs\",\"id\":\"s\"},{\"name\":\"dystkiiuxhqyud\",\"type\":\"rrqnbpoczvyifqrv\",\"id\":\"vjsllrmvvdfw\"},{\"name\":\"pnpulexxbczwtru\",\"type\":\"qzbqjvsov\",\"id\":\"okacspk\"},{\"name\":\"zdobpxjmflbvvnch\",\"type\":\"cciw\",\"id\":\"juqk\"}],\"backendPoolsSettings\":{\"enforceCertificateNameCheck\":\"Enabled\",\"sendRecvTimeoutSeconds\":2114864042},\"enabledState\":\"Enabled\"},\"location\":\"uo\",\"tags\":{\"sauuimj\":\"kg\",\"rfbyaosvexcso\":\"vxieduugidyj\",\"vleggzfbuhfmvfax\":\"pclhocohslk\"},\"id\":\"ffeii\",\"name\":\"hl\",\"type\":\"m\"}")
                .toObject(FrontDoorInner.class);
        Assertions.assertEquals("uo", model.location());
        Assertions.assertEquals("kg", model.tags().get("sauuimj"));
        Assertions.assertEquals("c", model.friendlyName());
        Assertions.assertEquals("jfeallnwsub", model.routingRules().get(0).id());
        Assertions.assertEquals("bacfionlebxetq", model.routingRules().get(0).name());
        Assertions.assertEquals("pusuesn", model.loadBalancingSettings().get(0).id());
        Assertions.assertEquals("pwlbjnpg", model.loadBalancingSettings().get(0).name());
        Assertions.assertEquals("vdcsitynn", model.healthProbeSettings().get(0).id());
        Assertions.assertEquals("ofqweykhmenevfye", model.healthProbeSettings().get(0).name());
        Assertions.assertEquals("jrefovgmkqsle", model.backendPools().get(0).id());
        Assertions.assertEquals("ctehfiqscjey", model.backendPools().get(0).name());
        Assertions.assertEquals("s", model.frontendEndpoints().get(0).id());
        Assertions.assertEquals("rdxwzywqsm", model.frontendEndpoints().get(0).name());
        Assertions
            .assertEquals(
                EnforceCertificateNameCheckEnabledState.ENABLED,
                model.backendPoolsSettings().enforceCertificateNameCheck());
        Assertions.assertEquals(2114864042, model.backendPoolsSettings().sendRecvTimeoutSeconds());
        Assertions.assertEquals(FrontDoorEnabledState.ENABLED, model.enabledState());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        FrontDoorInner model =
            new FrontDoorInner()
                .withLocation("uo")
                .withTags(mapOf("sauuimj", "kg", "rfbyaosvexcso", "vxieduugidyj", "vleggzfbuhfmvfax", "pclhocohslk"))
                .withFriendlyName("c")
                .withRoutingRules(
                    Arrays
                        .asList(
                            new RoutingRule().withId("jfeallnwsub").withName("bacfionlebxetq"),
                            new RoutingRule().withId("seiphe").withName("jampmngnzscxaqw"),
                            new RoutingRule().withId("umasxazjpq").withName("okeyyienj"),
                            new RoutingRule().withId("dgwdslfhot").withName("ualhbxxhejj")))
                .withLoadBalancingSettings(
                    Arrays
                        .asList(
                            new LoadBalancingSettingsModel().withId("pusuesn").withName("pwlbjnpg"),
                            new LoadBalancingSettingsModel().withId("vudwx").withName("ej"),
                            new LoadBalancingSettingsModel().withId("jdyggdtji").withName("nvowgujju")))
                .withHealthProbeSettings(
                    Arrays.asList(new HealthProbeSettingsModel().withId("vdcsitynn").withName("ofqweykhmenevfye")))
                .withBackendPools(
                    Arrays
                        .asList(
                            new BackendPool().withId("jrefovgmkqsle").withName("ctehfiqscjey"),
                            new BackendPool().withId("hvmdajvnysounq").withName("xyqj"),
                            new BackendPool().withId("okth").withName("noae"),
                            new BackendPool().withId("axbezyiuo").withName("uaodsfcpk")))
                .withFrontendEndpoints(
                    Arrays
                        .asList(
                            new FrontendEndpointInner().withId("s").withName("rdxwzywqsm"),
                            new FrontendEndpointInner().withId("vjsllrmvvdfw").withName("dystkiiuxhqyud"),
                            new FrontendEndpointInner().withId("okacspk").withName("pnpulexxbczwtru"),
                            new FrontendEndpointInner().withId("juqk").withName("zdobpxjmflbvvnch")))
                .withBackendPoolsSettings(
                    new BackendPoolsSettings()
                        .withEnforceCertificateNameCheck(EnforceCertificateNameCheckEnabledState.ENABLED)
                        .withSendRecvTimeoutSeconds(2114864042))
                .withEnabledState(FrontDoorEnabledState.ENABLED);
        model = BinaryData.fromObject(model).toObject(FrontDoorInner.class);
        Assertions.assertEquals("uo", model.location());
        Assertions.assertEquals("kg", model.tags().get("sauuimj"));
        Assertions.assertEquals("c", model.friendlyName());
        Assertions.assertEquals("jfeallnwsub", model.routingRules().get(0).id());
        Assertions.assertEquals("bacfionlebxetq", model.routingRules().get(0).name());
        Assertions.assertEquals("pusuesn", model.loadBalancingSettings().get(0).id());
        Assertions.assertEquals("pwlbjnpg", model.loadBalancingSettings().get(0).name());
        Assertions.assertEquals("vdcsitynn", model.healthProbeSettings().get(0).id());
        Assertions.assertEquals("ofqweykhmenevfye", model.healthProbeSettings().get(0).name());
        Assertions.assertEquals("jrefovgmkqsle", model.backendPools().get(0).id());
        Assertions.assertEquals("ctehfiqscjey", model.backendPools().get(0).name());
        Assertions.assertEquals("s", model.frontendEndpoints().get(0).id());
        Assertions.assertEquals("rdxwzywqsm", model.frontendEndpoints().get(0).name());
        Assertions
            .assertEquals(
                EnforceCertificateNameCheckEnabledState.ENABLED,
                model.backendPoolsSettings().enforceCertificateNameCheck());
        Assertions.assertEquals(2114864042, model.backendPoolsSettings().sendRecvTimeoutSeconds());
        Assertions.assertEquals(FrontDoorEnabledState.ENABLED, model.enabledState());
    }

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