// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.chronicle.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.Chronicle.V1";
option go_package = "cloud.google.com/go/chronicle/apiv1/chroniclepb;chroniclepb";
option java_multiple_files = true;
option java_outer_classname = "BigQueryExportProto";
option java_package = "com.google.cloud.chronicle.v1";
option php_namespace = "Google\\Cloud\\Chronicle\\V1";
option ruby_package = "Google::Cloud::Chronicle::V1";

// Service for managing BigQuery export configurations for Chronicle instances.
service BigQueryExportService {
  option (google.api.default_host) = "chronicle.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/chronicle,"
      "https://www.googleapis.com/auth/chronicle.readonly,"
      "https://www.googleapis.com/auth/cloud-platform";

  // Get the BigQuery export configuration for a Chronicle instance.
  rpc GetBigQueryExport(GetBigQueryExportRequest) returns (BigQueryExport) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/instances/*/bigQueryExport}"
    };
    option (google.api.method_signature) = "name";
  }

  // Update the BigQuery export configuration for a Chronicle instance.
  rpc UpdateBigQueryExport(UpdateBigQueryExportRequest)
      returns (BigQueryExport) {
    option (google.api.http) = {
      patch: "/v1/{big_query_export.name=projects/*/locations/*/instances/*/bigQueryExport}"
      body: "big_query_export"
    };
    option (google.api.method_signature) = "big_query_export,update_mask";
  }

  // Provision the BigQuery export for a Chronicle instance. This will create
  // {{gcp_name}} resources like {{storage_name}} buckets, BigQuery datasets
  // and set default export settings for each data source.
  rpc ProvisionBigQueryExport(ProvisionBigQueryExportRequest)
      returns (BigQueryExport) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/instances/*}/bigQueryExport:provision"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
  }
}

// The BigQueryExportPackage entitled for the Chronicle instance.
enum BigQueryExportPackage {
  // The BigQueryExportPackage is unspecified.
  BIG_QUERY_EXPORT_PACKAGE_UNSPECIFIED = 0;

  // The BigQueryExportPackage is Bring Your Own BigQuery.
  BIG_QUERY_EXPORT_PACKAGE_BYOBQ = 1;

  // The BigQueryExportPackage is Advanced BigQuery.
  BIG_QUERY_EXPORT_PACKAGE_ADVANCED = 2;
}

// The state of the latest data source export job.
enum LatestExportJobState {
  // The latest export job state is unspecified.
  LATEST_EXPORT_JOB_STATE_UNSPECIFIED = 0;

  // The latest export job state is successful.
  LATEST_EXPORT_JOB_STATE_SUCCESS = 1;

  // The latest export job state is failed.
  LATEST_EXPORT_JOB_STATE_FAILED = 2;
}

// This resource represents the BigQuery export configuration for a Chronicle
// instance which includes Google Cloud Platform resources like Cloud Storage
// buckets, BigQuery datasets etc and the export settings for each data source.
message BigQueryExport {
  option (google.api.resource) = {
    type: "chronicle.googleapis.com/BigQueryExport"
    pattern: "projects/{project}/locations/{location}/instances/{instance}/bigQueryExport"
    plural: "bigQueryExport"
    singular: "bigQueryExport"
  };

  // Identifier. The resource name of the BigQueryExport.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/bigQueryExport
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. Whether the BigQueryExport has been provisioned for the
  // Chronicle instance.
  bool provisioned = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The BigQueryExportPackage entitled for the Chronicle instance.
  BigQueryExportPackage big_query_export_package = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The export settings for the Entity Graph data source.
  DataSourceExportSettings entity_graph_settings = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The export settings for the IOC Matches data source.
  DataSourceExportSettings ioc_matches_settings = 5
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The export settings for the Rule Detections data source.
  DataSourceExportSettings rule_detections_settings = 6
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The export settings for the UDM Events Aggregates data source.
  DataSourceExportSettings udm_events_aggregates_settings = 7
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The export settings for the UDM Events data source.
  DataSourceExportSettings udm_events_settings = 8
      [(google.api.field_behavior) = OPTIONAL];
}

// The export settings for a data source.
message DataSourceExportSettings {
  // Required. Whether the data source is enabled for export.
  bool enabled = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The retention period for the data source in days.
  int32 retention_days = 2 [(google.api.field_behavior) = REQUIRED];

  // Output only. The state of the latest data source export job.
  LatestExportJobState latest_export_job_state = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The data freshness of the given export which represents the
  // time bucket at which the latest event was exported.
  google.protobuf.Timestamp data_freshness_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The stored data volume of all the exports.
  int64 data_volume = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The request message to fetch BigQuery Export configuration.
message GetBigQueryExportRequest {
  // Required. The resource name of the BigqueryExport to retrieve.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/bigQueryExport
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/BigQueryExport"
    }
  ];
}

// The request message to update BigQuery Export configuration.
message UpdateBigQueryExportRequest {
  // Required. The BigQueryExport settings to update.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/bigQueryExport
  BigQueryExport big_query_export = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The list of fields to update.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// The request message to provision BigQuery Export configuration.
message ProvisionBigQueryExportRequest {
  // Required. The instance for which BigQuery export is being provisioned.
  // Format: projects/{project}/locations/{location}/instances/{instance}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "chronicle.googleapis.com/BigQueryExport"
    }
  ];
}
