// 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.datacatalog.lineage.configmanagement.v1;

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

option csharp_namespace = "Google.Cloud.DataCatalog.Lineage.ConfigManagement.V1";
option go_package = "cloud.google.com/go/datacatalog/lineage/configmanagement/apiv1/configmanagementpb;configmanagementpb";
option java_multiple_files = true;
option java_outer_classname = "ConfigManagementProto";
option java_package = "com.google.cloud.datacatalog.lineage.configmanagement.v1";
option php_namespace = "Google\\Cloud\\DataCatalog\\Lineage\\ConfigManagement\\V1";
option ruby_package = "Google::Cloud::DataCatalog::Lineage::ConfigManagement::V1";

// Lineage Config Management service. Config Management service is used to
// manage the configuration for Data Lineage. These Configs define different
// configuration options for Lineage customers to control behaviour of lineage
// systems.
service ConfigManagementService {
  option (google.api.default_host) = "datalineage.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Get the Config for a given resource.
  rpc GetConfig(GetConfigRequest) returns (Config) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/config}"
      additional_bindings { get: "/v1/{name=folders/*/locations/*/config}" }
      additional_bindings {
        get: "/v1/{name=organizations/*/locations/*/config}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // Update the Config for a given resource.
  rpc UpdateConfig(UpdateConfigRequest) returns (Config) {
    option (google.api.http) = {
      patch: "/v1/{config.name=projects/*/locations/*/config}"
      body: "config"
      additional_bindings {
        patch: "/v1/{config.name=folders/*/locations/*/config}"
        body: "config"
      }
      additional_bindings {
        patch: "/v1/{config.name=organizations/*/locations/*/config}"
        body: "config"
      }
    };
    option (google.api.method_signature) = "config";
  }
}

// Request message for GetConfig RPC.
message GetConfigRequest {
  // Required. REQUIRED: The resource name of the config to be fetched.
  // Format:
  // `organizations/{organization_id}/locations/global/config`
  // `folders/{folder_id}/locations/global/config`
  // `projects/{project_id}/locations/global/config`
  // `projects/{project_number}/locations/global/config`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datalineage.googleapis.com/Config"
    }
  ];
}

// Request message for UpdateConfig RPC.
message UpdateConfigRequest {
  // Required. REQUIRED: The config to be applied to the resource and all its
  // descendants.
  Config config = 1 [(google.api.field_behavior) = REQUIRED];
}

// Configuration for Data Lineage. Defines different configuration options for
// Lineage customers to control behaviour of lineage systems.
message Config {
  option (google.api.resource) = {
    type: "datalineage.googleapis.com/Config"
    pattern: "projects/{project}/locations/{location}/config"
    pattern: "folders/{folder}/locations/{location}/config"
    pattern: "organizations/{organization}/locations/{location}/config"
    plural: "configs"
    singular: "config"
  };

  // Defines how Lineage should be ingested for a given resource.
  message Ingestion {
    // Ingestion rule for Data Lineage ingestion.
    message IngestionRule {
      // Integration selector of the rule. The rule is only applied to the
      // Integration selected by the selector.
      message IntegrationSelector {
        // Integration to which the rule applies.
        // This enum is expected to grow over time.
        enum Integration {
          // Integration is Unspecified
          INTEGRATION_UNSPECIFIED = 0;

          // Dataproc
          DATAPROC = 2;

          // Looker Core
          LOOKER_CORE = 3;
        }

        // Required. Integration to which the rule applies.
        // This field can be used to specify the integration against which the
        // ingestion rule should be applied.
        Integration integration = 1 [(google.api.field_behavior) = REQUIRED];
      }

      // Lineage enablement configuration. Defines configurations for the
      // ingestion of lineage for the resource and its children.
      message LineageEnablement {
        // Optional. If true, ingestion of lineage should be enabled. If false,
        // it should be disabled. If unspecified, the system default value is
        // used.
        optional bool enabled = 1 [(google.api.field_behavior) = OPTIONAL];
      }

      // Required. Integration selector of the rule. The rule is only applied to
      // the Integration selected by the selector.
      IntegrationSelector integration_selector = 1
          [(google.api.field_behavior) = REQUIRED];

      // Required. Lineage enablement configuration. Defines configurations for
      // the ingestion of lineage for the resource and its children. If
      // unspecified, the ingestion will be enabled only if it was configured in
      // the resource's parent.
      LineageEnablement lineage_enablement = 3
          [(google.api.field_behavior) = REQUIRED];
    }

    // Optional. List of rules for Data Lineage ingestion.
    repeated IngestionRule rules = 1 [(google.api.field_behavior) = OPTIONAL];
  }

  // Identifier. The resource name of the config.
  // Format:
  // `organizations/{organization_id}/locations/global/config`
  // `folders/{folder_id}/locations/global/config`
  // `projects/{project_id}/locations/global/config`
  // `projects/{project_number}/locations/global/config`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Optional. Ingestion rule for Data Lineage ingestion.
  Ingestion ingestion = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. `etag` is used for optimistic concurrency control as a way
  // to help prevent simultaneous updates of a config from overwriting each
  // other. It is required that systems make use of the `etag` in the
  // read-modify-write cycle to perform config updates in order to avoid race
  // conditions: An `etag` is returned in the response to `GetConfig`, and
  // systems are expected to put that etag in the request to `UpdateConfig` to
  // ensure that their change will be applied to the same version of the config.
  // If an `etag` is not provided in the call to `UpdateConfig`, then the
  // existing config, if any, will be overwritten.
  string etag = 3 [(google.api.field_behavior) = OPTIONAL];
}
