// 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.dataplex.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";

option go_package = "cloud.google.com/go/dataplex/apiv1/dataplexpb;dataplexpb";
option java_multiple_files = true;
option java_outer_classname = "DataDocumentationProto";
option java_package = "com.google.cloud.dataplex.v1";

// DataDocumentation scan related spec.
message DataDocumentationSpec {
  // The data documentation generation scope. This field contains the possible
  // components of a data documentation scan which can be selectively generated.
  enum GenerationScope {
    // Unspecified generation scope. If no generation scope is specified, all
    // available documentation components will be generated.
    GENERATION_SCOPE_UNSPECIFIED = 0;

    // All the possible results will be generated.
    ALL = 1;

    // Table and column descriptions will be generated.
    TABLE_AND_COLUMN_DESCRIPTIONS = 2;

    // SQL queries will be generated.
    SQL_QUERIES = 3;
  }

  // Optional. Whether to publish result to Dataplex Catalog.
  bool catalog_publishing_enabled = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Specifies which components of the data documentation to generate.
  // Any component that is required to generate the specified components will
  // also be generated. If no generation scope is specified, all available
  // documentation components will be generated.
  repeated GenerationScope generation_scopes = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// The output of a DataDocumentation scan.
message DataDocumentationResult {
  // Insights for a dataset resource.
  message DatasetResult {
    // Output only. Generated Dataset description.
    string overview = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Relationships suggesting how tables in the dataset are
    // related to each other, based on their schema.
    repeated SchemaRelationship schema_relationships = 3
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Sample SQL queries for the dataset.
    repeated Query queries = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Insights for a table resource.
  message TableResult {
    // Output only. The service-qualified full resource name of the cloud
    // resource. Ex:
    // //bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID
    string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Generated description of the table.
    string overview = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Schema of the table with generated metadata of the columns
    // in the schema.
    Schema schema = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Sample SQL queries for the table.
    repeated Query queries = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Details of the relationship between the schema of two resources.
  message SchemaRelationship {
    // Source which generated the schema relation edge.
    enum Source {
      // The source of the schema relationship is unspecified.
      SOURCE_UNSPECIFIED = 0;

      // The source of the schema relationship is agent.
      AGENT = 4;

      // The source of the schema relationship is query history from the source
      // system.
      QUERY_HISTORY = 5;

      // The source of the schema relationship is table constraints added in
      // the source system.
      TABLE_CONSTRAINTS = 6;
    }

    // The type of relationship.
    enum Type {
      // The type of the schema relationship is unspecified.
      TYPE_UNSPECIFIED = 0;

      // Indicates a join relationship between the schema fields.
      SCHEMA_JOIN = 1;
    }

    // Represents an ordered set of paths within a table's schema.
    message SchemaPaths {
      // Output only. The service-qualified full resource name of the table
      // Ex:
      // //bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID
      string table_fqn = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

      // Output only. An ordered set of Paths to fields within the schema of the
      // table. For fields nested within a top level field of type record, use
      // '.' to separate field names. Examples: Top level field - `top_level`
      // Nested field - `top_level.child.sub_field`
      repeated string paths = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
    }

    // Output only. An ordered list of fields for the join from the first table.
    // The size of this list must be the same as `right_schema_paths`.
    // Each field at index i in this list must correspond to a field at the same
    // index in the `right_schema_paths` list.
    SchemaPaths left_schema_paths = 1
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. An ordered list of fields for the join from the second
    // table. The size of this list must be the same as `left_schema_paths`.
    // Each field at index i in this list must correspond to a field at the same
    // index in the `left_schema_paths` list.
    SchemaPaths right_schema_paths = 2
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Sources which generated the schema relation edge.
    repeated Source sources = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The type of relationship between the schema paths.
    Type type = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // A sample SQL query in data documentation.
  message Query {
    // Output only. The SQL query string which can be executed.
    string sql = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The description for the query.
    string description = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Schema of the table with generated metadata of columns.
  message Schema {
    // Output only. The list of columns.
    repeated Field fields = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Column of a table with generated metadata and nested fields.
  message Field {
    // Output only. The name of the column.
    string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Generated description for columns and fields.
    string description = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Nested fields.
    repeated Field fields = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // The result of the data documentation scan.
  oneof result {
    // Output only. Insights for a Dataset resource.
    DatasetResult dataset_result = 7
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Insights for a Table resource.
    TableResult table_result = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
  }
}
