# 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).

require 'oci'
require 'date'

# Create a default config using DEFAULT profile in default location
# Refer to https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File for more info
config = OCI::ConfigFileLoader.load_config

# Initialize service client with default config file
usage_api_client = OCI::UsageApi::UsageapiClient.new(config: config)

# Send the request to service, some parameters are not required, see API doc for more info
update_usage_carbon_emissions_query_response =
  usage_api_client.update_usage_carbon_emissions_query(
    OCI::UsageApi::Models::UpdateUsageCarbonEmissionsQueryDetails.new(
      query_definition:
        OCI::UsageApi::Models::UsageCarbonEmissionsQueryDefinition.new(
          display_name: 'EXAMPLE-displayName-Value',
          report_query:
            OCI::UsageApi::Models::UsageCarbonEmissionsReportQuery.new(
              tenant_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value',
              time_usage_started: DateTime.parse('2012-11-22T01:44:53.201Z'),
              time_usage_ended: DateTime.parse('2002-07-07T06:10:09.047Z'),
              is_aggregate_by_time: true,
              group_by: %w[EXAMPLE--Value],
              group_by_tag: [
                OCI::UsageApi::Models::Tag.new(
                  namespace: 'EXAMPLE-namespace-Value',
                  key: 'EXAMPLE-key-Value',
                  value: 'EXAMPLE-value-Value'
                )
              ],
              compartment_depth: 4,
              filter:
                OCI::UsageApi::Models::Filter.new(
                  operator: 'AND',
                  dimensions: [
                    OCI::UsageApi::Models::Dimension.new(
                      key: 'EXAMPLE-key-Value', value: 'EXAMPLE-value-Value'
                    )
                  ],
                  tags: [
                    OCI::UsageApi::Models::Tag.new(
                      namespace: 'EXAMPLE-namespace-Value',
                      key: 'EXAMPLE-key-Value',
                      value: 'EXAMPLE-value-Value'
                    )
                  ]
                ),
              date_range_name: 'LAST_THREE_MONTHS'
            ),
          cost_analysis_ui:
            OCI::UsageApi::Models::CostAnalysisUI.new(
              graph: 'BARS', is_cumulative_graph: true
            ),
          version: 7067
        )
    ),
    'ocid1.test.oc1..<unique_ID>EXAMPLE-usageCarbonEmissionsQueryId-Value'
  )

# Get the data from response
puts "#{update_usage_carbon_emissions_query_response.data}"