// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).

import * as waas from "oci-waas";
import common = require("oci-common");

// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.

const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();

(async () => {
  try {
    // Create a service client
    const client = new waas.WaasClient({ authenticationDetailsProvider: provider });

    // Create a request and dependent object(s).
    const createWaasPolicyDetails = ({
      compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
      displayName: "EXAMPLE-displayName-Value",
      domain: "EXAMPLE-domain-Value",
      additionalDomains: ["EXAMPLE--Value"],
      origins: {
        EXAMPLE_KEY_6TTXq: ({
          uri: "EXAMPLE-uri-Value",
          httpPort: 43331,
          httpsPort: 26175,
          customHeaders: [
            ({
              name: "EXAMPLE-name-Value",
              value: "EXAMPLE-value-Value"
            } as unknown) as waas.models.Header
          ]
        } as unknown) as waas.models.Origin
      },
      originGroups: {
        EXAMPLE_KEY_bMjNq: ({
          origins: [
            ({
              origin: "EXAMPLE-origin-Value",
              weight: 5617
            } as unknown) as waas.models.OriginGroupOrigins
          ]
        } as unknown) as waas.models.OriginGroup
      },
      policyConfig: ({
        certificateId: "ocid1.test.oc1..<unique_ID>EXAMPLE-certificateId-Value",
        isHttpsEnabled: false,
        isHttpsForced: false,
        tlsProtocols: [waas.models.PolicyConfig.TlsProtocols.TlsV13],
        isOriginCompressionEnabled: true,
        isBehindCdn: false,
        clientAddressHeader: waas.models.PolicyConfig.ClientAddressHeader.XRealIp,
        isCacheControlRespected: false,
        isResponseBufferingEnabled: false,
        cipherGroup: waas.models.PolicyConfig.CipherGroup.Default,
        loadBalancingMethod: ({
          method: "STICKY_COOKIE",
          name: "EXAMPLE-name-Value",
          domain: "EXAMPLE-domain-Value",
          expirationTimeInSeconds: 19454537
        } as unknown) as waas.models.StickyCookieLoadBalancingMethod,
        websocketPathPrefixes: ["EXAMPLE--Value"],
        isSniEnabled: true,
        healthChecks: ({
          isEnabled: true,
          method: waas.models.HealthCheck.Method.Post,
          path: "EXAMPLE-path-Value",
          headers: {
            EXAMPLE_KEY_Tu3uZ: "EXAMPLE_VALUE_BqGvBGQwzBclZ86VUi97"
          },
          expectedResponseCodeGroup: [waas.models.HealthCheck.ExpectedResponseCodeGroup._5Xx],
          isResponseTextCheckEnabled: true,
          expectedResponseText: "EXAMPLE-expectedResponseText-Value",
          intervalInSeconds: 41,
          timeoutInSeconds: 40,
          healthyThreshold: 19,
          unhealthyThreshold: 14
        } as unknown) as waas.models.HealthCheck
      } as unknown) as waas.models.PolicyConfig,
      wafConfig: ({
        accessRules: [
          ({
            name: "EXAMPLE-name-Value",
            criteria: [
              ({
                condition: waas.models.AccessRuleCriteria.Condition.HttpMethodIs,
                value: "EXAMPLE-value-Value",
                isCaseSensitive: false
              } as unknown) as waas.models.AccessRuleCriteria
            ],
            action: waas.models.AccessRule.Action.Block,
            blockAction: waas.models.AccessRule.BlockAction.ShowErrorPage,
            blockResponseCode: 503,
            blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
            blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
            blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
            bypassChallenges: [waas.models.AccessRule.BypassChallenges.Captcha],
            redirectUrl: "EXAMPLE-redirectUrl-Value",
            redirectResponseCode: waas.models.AccessRule.RedirectResponseCode.MovedPermanently,
            captchaTitle: "EXAMPLE-captchaTitle-Value",
            captchaHeader: "EXAMPLE-captchaHeader-Value",
            captchaFooter: "EXAMPLE-captchaFooter-Value",
            captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value",
            responseHeaderManipulation: [
              ({
                action: "ADD_HTTP_RESPONSE_HEADER",
                header: "EXAMPLE-header-Value",
                value: "EXAMPLE-value-Value"
              } as unknown) as waas.models.AddHttpResponseHeaderAction
            ]
          } as unknown) as waas.models.AccessRule
        ],
        addressRateLimiting: ({
          isEnabled: true,
          allowedRatePerAddress: 5898,
          maxDelayedCountPerAddress: 761,
          blockResponseCode: 354
        } as unknown) as waas.models.AddressRateLimiting,
        captchas: [
          ({
            url: "EXAMPLE-url-Value",
            sessionExpirationInSeconds: 238891,
            title: "EXAMPLE-title-Value",
            headerText: "EXAMPLE-headerText-Value",
            footerText: "EXAMPLE-footerText-Value",
            failureMessage: "EXAMPLE-failureMessage-Value",
            submitLabel: "EXAMPLE-submitLabel-Value"
          } as unknown) as waas.models.Captcha
        ],
        deviceFingerprintChallenge: ({
          isEnabled: false,
          action: waas.models.DeviceFingerprintChallenge.Action.Block,
          failureThreshold: 524976,
          actionExpirationInSeconds: 248261,
          failureThresholdExpirationInSeconds: 301111,
          maxAddressCount: 5634,
          maxAddressCountExpirationInSeconds: 333160,
          challengeSettings: ({
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowErrorPage,
            blockResponseCode: 799,
            blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
            blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
            blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
            captchaTitle: "EXAMPLE-captchaTitle-Value",
            captchaHeader: "EXAMPLE-captchaHeader-Value",
            captchaFooter: "EXAMPLE-captchaFooter-Value",
            captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
          } as unknown) as waas.models.BlockChallengeSettings
        } as unknown) as waas.models.DeviceFingerprintChallenge,
        humanInteractionChallenge: ({
          isEnabled: true,
          action: waas.models.HumanInteractionChallenge.Action.Detect,
          failureThreshold: 512899,
          actionExpirationInSeconds: 43675,
          failureThresholdExpirationInSeconds: 192941,
          interactionThreshold: 75,
          recordingPeriodInSeconds: 6205,
          setHttpHeader: ({
            name: "EXAMPLE-name-Value",
            value: "EXAMPLE-value-Value"
          } as unknown) as waas.models.Header,
          challengeSettings: ({
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowCaptcha,
            blockResponseCode: 665,
            blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
            blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
            blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
            captchaTitle: "EXAMPLE-captchaTitle-Value",
            captchaHeader: "EXAMPLE-captchaHeader-Value",
            captchaFooter: "EXAMPLE-captchaFooter-Value",
            captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
          } as unknown) as waas.models.BlockChallengeSettings,
          isNatEnabled: true
        } as unknown) as waas.models.HumanInteractionChallenge,
        jsChallenge: ({
          isEnabled: false,
          action: waas.models.JsChallenge.Action.Detect,
          failureThreshold: 397201,
          actionExpirationInSeconds: 78335,
          setHttpHeader: ({
            name: "EXAMPLE-name-Value",
            value: "EXAMPLE-value-Value"
          } as unknown) as waas.models.Header,
          challengeSettings: ({
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowErrorPage,
            blockResponseCode: 613,
            blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
            blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
            blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
            captchaTitle: "EXAMPLE-captchaTitle-Value",
            captchaHeader: "EXAMPLE-captchaHeader-Value",
            captchaFooter: "EXAMPLE-captchaFooter-Value",
            captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
          } as unknown) as waas.models.BlockChallengeSettings,
          areRedirectsChallenged: false,
          criteria: [
            ({
              condition: waas.models.AccessRuleCriteria.Condition.UrlRegex,
              value: "EXAMPLE-value-Value",
              isCaseSensitive: true
            } as unknown) as waas.models.AccessRuleCriteria
          ],
          isNatEnabled: false
        } as unknown) as waas.models.JsChallenge,
        origin: "EXAMPLE-origin-Value",
        cachingRules: [
          ({
            key: "EXAMPLE-key-Value",
            name: "EXAMPLE-name-Value",
            action: waas.models.CachingRule.Action.BypassCache,
            cachingDuration: "EXAMPLE-cachingDuration-Value",
            isClientCachingEnabled: false,
            clientCachingDuration: "EXAMPLE-clientCachingDuration-Value",
            criteria: [
              ({
                condition: waas.models.CachingRuleCriteria.Condition.UrlPartEndsWith,
                value: "EXAMPLE-value-Value"
              } as unknown) as waas.models.CachingRuleCriteria
            ]
          } as unknown) as waas.models.CachingRule
        ],
        customProtectionRules: [
          ({
            id: "ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value",
            action: waas.models.CustomProtectionRuleSetting.Action.Block,
            exclusions: [
              ({
                target: waas.models.ProtectionRuleExclusion.Target.RequestCookies,
                exclusions: ["EXAMPLE--Value"]
              } as unknown) as waas.models.ProtectionRuleExclusion
            ]
          } as unknown) as waas.models.CustomProtectionRuleSetting
        ],
        originGroups: ["EXAMPLE--Value"],
        protectionSettings: ({
          blockAction: waas.models.ProtectionSettings.BlockAction.ShowErrorPage,
          blockResponseCode: 511,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          maxArgumentCount: 6042,
          maxNameLengthPerArgument: 91547,
          maxTotalNameLengthOfArguments: 268639,
          recommendationsPeriodInDays: 44,
          isResponseInspected: false,
          maxResponseSizeInKiB: 302,
          allowedHttpMethods: [waas.models.ProtectionSettings.AllowedHttpMethods.Get],
          mediaTypes: ["EXAMPLE--Value"]
        } as unknown) as waas.models.ProtectionSettings,
        whitelists: [
          ({
            name: "EXAMPLE-name-Value",
            addresses: ["EXAMPLE--Value"],
            addressLists: ["EXAMPLE--Value"]
          } as unknown) as waas.models.Whitelist
        ]
      } as unknown) as waas.models.WafConfigDetails,
      freeformTags: {
        EXAMPLE_KEY_0MzNf: "EXAMPLE_VALUE_4CvR5g5V5mNEr20V8z04"
      },
      definedTags: {
        EXAMPLE_KEY_lgF2F: {
          EXAMPLE_KEY_tk9BP: "EXAMPLE--Value"
        }
      }
    } as unknown) as waas.models.CreateWaasPolicyDetails;

    const createWaasPolicyRequest: waas.requests.CreateWaasPolicyRequest = {
      createWaasPolicyDetails: createWaasPolicyDetails,
      opcRequestId: "VUYQUCEZXQZJ2PY5JFNF<unique_ID>",
      opcRetryToken: "EXAMPLE-opcRetryToken-Value"
    };

    // Send request to the Client.
    const createWaasPolicyResponse = await client.createWaasPolicy(createWaasPolicyRequest);
  } catch (error) {
    console.log("createWaasPolicy Failed with error  " + error);
  }
})();