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

package com.azure.resourcemanager.appcontainers.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appcontainers.fluent.models.AuthConfigProperties;
import com.azure.resourcemanager.appcontainers.models.Apple;
import com.azure.resourcemanager.appcontainers.models.AuthPlatform;
import com.azure.resourcemanager.appcontainers.models.AzureActiveDirectory;
import com.azure.resourcemanager.appcontainers.models.AzureStaticWebApps;
import com.azure.resourcemanager.appcontainers.models.CookieExpiration;
import com.azure.resourcemanager.appcontainers.models.CookieExpirationConvention;
import com.azure.resourcemanager.appcontainers.models.CustomOpenIdConnectProvider;
import com.azure.resourcemanager.appcontainers.models.Facebook;
import com.azure.resourcemanager.appcontainers.models.ForwardProxy;
import com.azure.resourcemanager.appcontainers.models.ForwardProxyConvention;
import com.azure.resourcemanager.appcontainers.models.GitHub;
import com.azure.resourcemanager.appcontainers.models.GlobalValidation;
import com.azure.resourcemanager.appcontainers.models.Google;
import com.azure.resourcemanager.appcontainers.models.HttpSettings;
import com.azure.resourcemanager.appcontainers.models.HttpSettingsRoutes;
import com.azure.resourcemanager.appcontainers.models.IdentityProviders;
import com.azure.resourcemanager.appcontainers.models.Login;
import com.azure.resourcemanager.appcontainers.models.LoginRoutes;
import com.azure.resourcemanager.appcontainers.models.Nonce;
import com.azure.resourcemanager.appcontainers.models.Twitter;
import com.azure.resourcemanager.appcontainers.models.UnauthenticatedClientActionV2;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AuthConfigPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AuthConfigProperties model =
            BinaryData
                .fromString(
                    "{\"platform\":{\"enabled\":true,\"runtimeVersion\":\"sjtxukcdmp\"},\"globalValidation\":{\"unauthenticatedClientAction\":\"Return403\",\"redirectToProvider\":\"uanzwuxzdx\",\"excludedPaths\":[\"rlhm\",\"hfpmrqobmtukknr\",\"rtihfxtijbpz\",\"gnwzsymglzufc\"]},\"identityProviders\":{\"azureActiveDirectory\":{\"enabled\":false,\"isAutoProvisioned\":true},\"facebook\":{\"enabled\":false,\"graphApiVersion\":\"cbjy\"},\"gitHub\":{\"enabled\":false},\"google\":{\"enabled\":true},\"twitter\":{\"enabled\":true},\"apple\":{\"enabled\":false},\"azureStaticWebApps\":{\"enabled\":false},\"customOpenIdConnectProviders\":{\"y\":{\"enabled\":false}}},\"login\":{\"routes\":{\"logoutEndpoint\":\"b\"},\"preserveUrlFragmentsForLogins\":false,\"allowedExternalRedirectUrls\":[\"vd\"],\"cookieExpiration\":{\"convention\":\"FixedTime\",\"timeToExpiration\":\"tfwvukxgaudc\"},\"nonce\":{\"validateNonce\":false,\"nonceExpirationInterval\":\"jcny\"}},\"httpSettings\":{\"requireHttps\":true,\"routes\":{\"apiPrefix\":\"htnapczwlokjyem\"},\"forwardProxy\":{\"convention\":\"NoProxy\",\"customHostHeaderName\":\"pjoxzjnch\",\"customProtoHeaderName\":\"jspodmailzyde\"}}}")
                .toObject(AuthConfigProperties.class);
        Assertions.assertEquals(true, model.platform().enabled());
        Assertions.assertEquals("sjtxukcdmp", model.platform().runtimeVersion());
        Assertions
            .assertEquals(
                UnauthenticatedClientActionV2.RETURN403, model.globalValidation().unauthenticatedClientAction());
        Assertions.assertEquals("uanzwuxzdx", model.globalValidation().redirectToProvider());
        Assertions.assertEquals("rlhm", model.globalValidation().excludedPaths().get(0));
        Assertions.assertEquals(false, model.identityProviders().azureActiveDirectory().enabled());
        Assertions.assertEquals(true, model.identityProviders().azureActiveDirectory().isAutoProvisioned());
        Assertions.assertEquals(false, model.identityProviders().facebook().enabled());
        Assertions.assertEquals("cbjy", model.identityProviders().facebook().graphApiVersion());
        Assertions.assertEquals(false, model.identityProviders().gitHub().enabled());
        Assertions.assertEquals(true, model.identityProviders().google().enabled());
        Assertions.assertEquals(true, model.identityProviders().twitter().enabled());
        Assertions.assertEquals(false, model.identityProviders().apple().enabled());
        Assertions.assertEquals(false, model.identityProviders().azureStaticWebApps().enabled());
        Assertions.assertEquals(false, model.identityProviders().customOpenIdConnectProviders().get("y").enabled());
        Assertions.assertEquals("b", model.login().routes().logoutEndpoint());
        Assertions.assertEquals(false, model.login().preserveUrlFragmentsForLogins());
        Assertions.assertEquals("vd", model.login().allowedExternalRedirectUrls().get(0));
        Assertions.assertEquals(CookieExpirationConvention.FIXED_TIME, model.login().cookieExpiration().convention());
        Assertions.assertEquals("tfwvukxgaudc", model.login().cookieExpiration().timeToExpiration());
        Assertions.assertEquals(false, model.login().nonce().validateNonce());
        Assertions.assertEquals("jcny", model.login().nonce().nonceExpirationInterval());
        Assertions.assertEquals(true, model.httpSettings().requireHttps());
        Assertions.assertEquals("htnapczwlokjyem", model.httpSettings().routes().apiPrefix());
        Assertions.assertEquals(ForwardProxyConvention.NO_PROXY, model.httpSettings().forwardProxy().convention());
        Assertions.assertEquals("pjoxzjnch", model.httpSettings().forwardProxy().customHostHeaderName());
        Assertions.assertEquals("jspodmailzyde", model.httpSettings().forwardProxy().customProtoHeaderName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AuthConfigProperties model =
            new AuthConfigProperties()
                .withPlatform(new AuthPlatform().withEnabled(true).withRuntimeVersion("sjtxukcdmp"))
                .withGlobalValidation(
                    new GlobalValidation()
                        .withUnauthenticatedClientAction(UnauthenticatedClientActionV2.RETURN403)
                        .withRedirectToProvider("uanzwuxzdx")
                        .withExcludedPaths(Arrays.asList("rlhm", "hfpmrqobmtukknr", "rtihfxtijbpz", "gnwzsymglzufc")))
                .withIdentityProviders(
                    new IdentityProviders()
                        .withAzureActiveDirectory(
                            new AzureActiveDirectory().withEnabled(false).withIsAutoProvisioned(true))
                        .withFacebook(new Facebook().withEnabled(false).withGraphApiVersion("cbjy"))
                        .withGitHub(new GitHub().withEnabled(false))
                        .withGoogle(new Google().withEnabled(true))
                        .withTwitter(new Twitter().withEnabled(true))
                        .withApple(new Apple().withEnabled(false))
                        .withAzureStaticWebApps(new AzureStaticWebApps().withEnabled(false))
                        .withCustomOpenIdConnectProviders(
                            mapOf("y", new CustomOpenIdConnectProvider().withEnabled(false))))
                .withLogin(
                    new Login()
                        .withRoutes(new LoginRoutes().withLogoutEndpoint("b"))
                        .withPreserveUrlFragmentsForLogins(false)
                        .withAllowedExternalRedirectUrls(Arrays.asList("vd"))
                        .withCookieExpiration(
                            new CookieExpiration()
                                .withConvention(CookieExpirationConvention.FIXED_TIME)
                                .withTimeToExpiration("tfwvukxgaudc"))
                        .withNonce(new Nonce().withValidateNonce(false).withNonceExpirationInterval("jcny")))
                .withHttpSettings(
                    new HttpSettings()
                        .withRequireHttps(true)
                        .withRoutes(new HttpSettingsRoutes().withApiPrefix("htnapczwlokjyem"))
                        .withForwardProxy(
                            new ForwardProxy()
                                .withConvention(ForwardProxyConvention.NO_PROXY)
                                .withCustomHostHeaderName("pjoxzjnch")
                                .withCustomProtoHeaderName("jspodmailzyde")));
        model = BinaryData.fromObject(model).toObject(AuthConfigProperties.class);
        Assertions.assertEquals(true, model.platform().enabled());
        Assertions.assertEquals("sjtxukcdmp", model.platform().runtimeVersion());
        Assertions
            .assertEquals(
                UnauthenticatedClientActionV2.RETURN403, model.globalValidation().unauthenticatedClientAction());
        Assertions.assertEquals("uanzwuxzdx", model.globalValidation().redirectToProvider());
        Assertions.assertEquals("rlhm", model.globalValidation().excludedPaths().get(0));
        Assertions.assertEquals(false, model.identityProviders().azureActiveDirectory().enabled());
        Assertions.assertEquals(true, model.identityProviders().azureActiveDirectory().isAutoProvisioned());
        Assertions.assertEquals(false, model.identityProviders().facebook().enabled());
        Assertions.assertEquals("cbjy", model.identityProviders().facebook().graphApiVersion());
        Assertions.assertEquals(false, model.identityProviders().gitHub().enabled());
        Assertions.assertEquals(true, model.identityProviders().google().enabled());
        Assertions.assertEquals(true, model.identityProviders().twitter().enabled());
        Assertions.assertEquals(false, model.identityProviders().apple().enabled());
        Assertions.assertEquals(false, model.identityProviders().azureStaticWebApps().enabled());
        Assertions.assertEquals(false, model.identityProviders().customOpenIdConnectProviders().get("y").enabled());
        Assertions.assertEquals("b", model.login().routes().logoutEndpoint());
        Assertions.assertEquals(false, model.login().preserveUrlFragmentsForLogins());
        Assertions.assertEquals("vd", model.login().allowedExternalRedirectUrls().get(0));
        Assertions.assertEquals(CookieExpirationConvention.FIXED_TIME, model.login().cookieExpiration().convention());
        Assertions.assertEquals("tfwvukxgaudc", model.login().cookieExpiration().timeToExpiration());
        Assertions.assertEquals(false, model.login().nonce().validateNonce());
        Assertions.assertEquals("jcny", model.login().nonce().nonceExpirationInterval());
        Assertions.assertEquals(true, model.httpSettings().requireHttps());
        Assertions.assertEquals("htnapczwlokjyem", model.httpSettings().routes().apiPrefix());
        Assertions.assertEquals(ForwardProxyConvention.NO_PROXY, model.httpSettings().forwardProxy().convention());
        Assertions.assertEquals("pjoxzjnch", model.httpSettings().forwardProxy().customHostHeaderName());
        Assertions.assertEquals("jspodmailzyde", model.httpSettings().forwardProxy().customProtoHeaderName());
    }

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