// 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 networkloadbalancer from "oci-networkloadbalancer";
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 networkloadbalancer.NetworkLoadBalancerClient({
      authenticationDetailsProvider: provider
    });

    // Create a request and dependent object(s).
    const createNetworkLoadBalancerDetails = {
      compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
      displayName: "EXAMPLE-displayName-Value",
      isPreserveSourceDestination: false,
      isSymmetricHashEnabled: false,
      reservedIps: [
        {
          id: "ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value"
        }
      ],
      isPrivate: true,
      subnetId: "ocid1.test.oc1..<unique_ID>EXAMPLE-subnetId-Value",
      networkSecurityGroupIds: ["EXAMPLE--Value"],
      nlbIpVersion: networkloadbalancer.models.NlbIpVersion.Ipv4AndIpv6,
      subnetIpv6Cidr: "EXAMPLE-subnetIpv6Cidr-Value",
      assignedPrivateIpv4: "EXAMPLE-assignedPrivateIpv4-Value",
      assignedIpv6: "EXAMPLE-assignedIpv6-Value",
      listeners: {
        EXAMPLE_KEY_YmOum: {
          name: "EXAMPLE-name-Value",
          defaultBackendSetName: "EXAMPLE-defaultBackendSetName-Value",
          ipVersion: networkloadbalancer.models.IpVersion.Ipv6,
          port: 144,
          protocol: networkloadbalancer.models.ListenerProtocols.Tcp,
          isPpv2Enabled: true
        }
      },
      backendSets: {
        EXAMPLE_KEY_IRBib: {
          policy: networkloadbalancer.models.NetworkLoadBalancingPolicy.ThreeTuple,
          ipVersion: networkloadbalancer.models.IpVersion.Ipv6,
          isPreserveSource: false,
          isFailOpen: false,
          isInstantFailoverEnabled: false,
          backends: [
            {
              name: "EXAMPLE-name-Value",
              ipAddress: "EXAMPLE-ipAddress-Value",
              targetId: "ocid1.test.oc1..<unique_ID>EXAMPLE-targetId-Value",
              port: 293,
              weight: 984,
              isDrain: true,
              isBackup: true,
              isOffline: false
            }
          ],
          healthChecker: {
            protocol: networkloadbalancer.models.HealthCheckProtocols.Udp,
            port: 766,
            retries: 690,
            timeoutInMillis: 687,
            intervalInMillis: 11,
            urlPath: "EXAMPLE-urlPath-Value",
            responseBodyRegex: "EXAMPLE-responseBodyRegex-Value",
            returnCode: 675,
            requestData: "some Byte data",
            responseData: "some Byte data",
            dns: {
              transportProtocol: networkloadbalancer.models.DnsHealthCheckTransportProtocols.Tcp,
              domainName: "EXAMPLE-domainName-Value",
              queryClass: networkloadbalancer.models.DnsHealthCheckQueryClasses.Ch,
              queryType: networkloadbalancer.models.DnsHealthCheckQueryTypes.A,
              rcodes: [
                networkloadbalancer.models.DnsHealthCheckRCodes.Noerror,
                networkloadbalancer.models.DnsHealthCheckRCodes.Servfail,
                networkloadbalancer.models.DnsHealthCheckRCodes.Nxdomain,
                networkloadbalancer.models.DnsHealthCheckRCodes.Refused
              ]
            }
          }
        }
      },
      freeformTags: {
        EXAMPLE_KEY_MDKiW: "EXAMPLE_VALUE_vnk27J3LhK8m6LzWJEG5"
      },
      definedTags: {
        EXAMPLE_KEY_H99F4: {
          EXAMPLE_KEY_jkaBQ: "EXAMPLE--Value"
        }
      }
    };

    const createNetworkLoadBalancerRequest: networkloadbalancer.requests.CreateNetworkLoadBalancerRequest = {
      createNetworkLoadBalancerDetails: createNetworkLoadBalancerDetails,
      opcRetryToken: "EXAMPLE-opcRetryToken-Value",
      opcRequestId: "RAXEWYEONPXKY7EGWP1E<unique_ID>"
    };

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