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

    // Create a request and dependent object(s).
    const updateQueryDetails = {
      queryDefinition: {
        displayName: "EXAMPLE-displayName-Value",
        reportQuery: {
          tenantId: "ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
          timeUsageStarted: new Date("Tue Aug 28 05:50:24 UTC 2001"),
          timeUsageEnded: new Date("Fri Jun 10 02:18:56 UTC 2039"),
          granularity: usageapi.models.ReportQuery.Granularity.Total,
          isAggregateByTime: true,
          forecast: {
            forecastType: usageapi.models.Forecast.ForecastType.Basic,
            timeForecastStarted: new Date("Sat Apr 20 08:24:13 UTC 2030"),
            timeForecastEnded: new Date("Fri Apr 14 08:45:30 UTC 2000")
          },
          queryType: usageapi.models.ReportQuery.QueryType.Allcredit,
          groupBy: ["EXAMPLE--Value"],
          groupByTag: [
            {
              namespace: "EXAMPLE-namespace-Value",
              key: "EXAMPLE-key-Value",
              value: "EXAMPLE-value-Value"
            }
          ],
          compartmentDepth: 4.520866,
          filter: {
            operator: usageapi.models.Filter.Operator.And,
            dimensions: [
              {
                key: "EXAMPLE-key-Value",
                value: "EXAMPLE-value-Value"
              }
            ],
            tags: [
              {
                namespace: "EXAMPLE-namespace-Value",
                key: "EXAMPLE-key-Value",
                value: "EXAMPLE-value-Value"
              }
            ]
          },
          dateRangeName: usageapi.models.ReportQuery.DateRangeName.LastOneYear
        },
        costAnalysisUI: {
          graph: usageapi.models.CostAnalysisUI.Graph.Lines,
          isCumulativeGraph: false
        },
        version: 7070.045
      }
    };

    const updateQueryRequest: usageapi.requests.UpdateQueryRequest = {
      updateQueryDetails: updateQueryDetails,
      queryId: "ocid1.test.oc1..<unique_ID>EXAMPLE-queryId-Value",
      opcRequestId: "JDNRGLFJFGYQUSY7PJ01<unique_ID>",
      ifMatch: "EXAMPLE-ifMatch-Value"
    };

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