// Copyright 2019 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.v1beta1;

import "google/protobuf/timestamp.proto";

option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1;datacatalog";
option java_multiple_files = true;
option java_package = "com.google.cloud.datacatalog";

// Tags are used to attach custom metadata to Data Catalog resources. Tags
// conform to the specifications within their tag template.
message Tag {
  // Required when used in
  // [UpdateTagRequest][google.cloud.datacatalog.v1beta1.UpdateTagRequest]. The
  // resource name of the tag in URL format. For example,
  // projects/{project_id}/locations/{location}/entrygroups/{entry_group_id}/entries/{entry_id}/tags/{tag_id}",
  // where tag_id is a system-generated identifier. Note that this Tag may not
  // actually be stored in the location in this name.
  string name = 1;

  // Required. The resource name of the tag template that this tag uses. For
  // example,
  // projects/{project_id}/locations/{location}/tagTemplates/{tag_template_id}.
  // This field cannot be modified after creation.
  string template = 2;

  // Output only. The display name of the tag template.
  string template_display_name = 5;

  // Optional. The scope within the parent resource that this tag is attached
  // to. If not provided, the tag is attached to the parent resource itself.
  // Deleting the scope from the parent resource will delete all tags attached
  // to that scope. These fields cannot be updated after creation.
  oneof scope {
    // Resources like Entry can have schemas associated with them. This scope
    // allows users to attach tags to an individual column based on that schema.
    //
    // For attaching a tag to a nested column, use '.' to separate the column
    // names: "outer_column.inner_column".
    string column = 4;
  }

  // Required. This maps the id of a tag field to the value of & additional
  // information about that field. Valid field IDs are defined by the tag's
  // template. A tag must have at least 1 field and at most 500 fields.
  map<string, TagField> fields = 3;
}

// Contains the value and supporting information for a field within
// a [Tag][google.cloud.datacatalog.v1beta1.Tag].
message TagField {
  // Holds an enum value.
  message EnumValue {
    // The display name of the enum value.
    string display_name = 1;
  }

  // Output only. The display name of this field.
  string display_name = 1;

  // Required. The value of this field.
  oneof kind {
    // Holds the value for a tag field with double type.
    double double_value = 2;

    // Holds the value for a tag field with string type.
    string string_value = 3;

    // Holds the value for a tag field with boolean type.
    bool bool_value = 4;

    // Holds the value for a tag field with timestamp type.
    google.protobuf.Timestamp timestamp_value = 5;

    // Holds the value for a tag field with enum type. This value must be
    // one of the allowed values in the definition of this enum.
    EnumValue enum_value = 6;
  }
}

// Tag templates defines the schema of the tags used to attach to Data Catalog
// resources. It defines the mapping of accepted field names and types that can
// be used within the tag. The tag template also controls the access to the tag.
message TagTemplate {
  // Required when used in
  // [UpdateTagTemplateRequest][google.cloud.datacatalog.v1beta1.UpdateTagTemplateRequest].
  // The resource name of the tag template in URL format. For example,
  // projects/{project_id}/locations/{location}/tagTemplates/{tag_template_id}.
  // Note that this TagTemplate and its child resources may not actually be
  // stored in the location in this name.
  string name = 1;

  // Optional. The display name for this template. Default value is an empty
  // string.
  string display_name = 2;

  // Required. Map of tag template field ids to the settings for the field.
  // This map is an exhaustive list of the allowed fields. This map must contain
  // at least one field and at most 500 fields.
  //
  // The keys to this map are tag template field IDs. Field IDs can contain
  // letters (both uppercase and lowercase), numbers (0-9) and underscores (_).
  // Field IDs must be at least 1 character long and at most 64 characters long.
  // Field IDs must start with a letter or underscore.
  map<string, TagTemplateField> fields = 3;
}

// The template for an individual field within a tag template.
message TagTemplateField {
  // Optional. The display name for this field. Default value is an empty
  // string.
  string display_name = 1;

  // Required. The type of value this tag field can contain.
  FieldType type = 2;
}

message FieldType {
  message EnumType {
    message EnumValue {
      // Required. The display name of the enum value. Must not be an empty
      // string.
      string display_name = 1;
    }

    // Required. The set of allowed values for this enum. This set must not be
    // empty, the display names of the values in this set must not be empty and
    // the display names of the values must be case-insensitively unique within
    // this set. Currently, enum values can only be added to the list of allowed
    // values. Deletion and renaming of enum values are not supported. Can have
    // up to 500 allowed values.
    repeated EnumValue allowed_values = 1;
  }

  enum PrimitiveType {
    // This is the default invalid value for a type.
    PRIMITIVE_TYPE_UNSPECIFIED = 0;

    // A double precision number.
    DOUBLE = 1;

    // An UTF-8 string.
    STRING = 2;

    // A boolean value.
    BOOL = 3;

    // A timestamp.
    TIMESTAMP = 4;
  }

  // Required.
  oneof type_decl {
    // Represents primitive types - string, bool etc.
    PrimitiveType primitive_type = 1;

    // Represents an enum type.
    EnumType enum_type = 2;
  }
}
