// Copyright 2020-2025 Buf Technologies, Inc.
//
// 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 buf.alpha.registry.v1alpha1;

import "google/protobuf/timestamp.proto";

message RepositoryTag {
  // primary key, unique.
  // tags are based on labels, so if a label has been moved, the ID will point to the
  // updated entry in the labels table.
  string id = 1;
  // immutable
  google.protobuf.Timestamp create_time = 2;
  // We reserve field number '3' for the update_time.
  // google.protobuf.Timestamp update_time = 3;
  // The name of the repository tag, e.g. "6e2e7f24718a76caa32a80d0e2b1841ef2c61403".
  string name = 4;
  // The name of the commit this tag belongs to.
  string commit_name = 5;
  // The username of the author of the tag.
  string author = 6;
}

// RepositoryTagService is the Repository tag service.
service RepositoryTagService {
  // GetRepositoryTag gets an existing repository tag.
  rpc GetRepositoryTag(GetRepositoryTagRequest) returns (GetRepositoryTagResponse) {
    option idempotency_level = IDEMPOTENT;
  }
  // CreateRepositoryTag creates a new repository tag.
  rpc CreateRepositoryTag(CreateRepositoryTagRequest) returns (CreateRepositoryTagResponse) {
    option idempotency_level = IDEMPOTENT;
  }
  // UpdateRepositoryTag update an existing repository tag.
  rpc UpdateRepositoryTag(UpdateRepositoryTagRequest) returns (UpdateRepositoryTagResponse) {
    option idempotency_level = IDEMPOTENT;
  }
  // ListRepositoryTags lists the repository tags associated with a Repository.
  rpc ListRepositoryTags(ListRepositoryTagsRequest) returns (ListRepositoryTagsResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
  // ListRepositoryTagsForReference lists the repository tags associated with a repository
  // reference name.
  rpc ListRepositoryTagsForReference(ListRepositoryTagsForReferenceRequest) returns (ListRepositoryTagsForReferenceResponse) {
    option idempotency_level = NO_SIDE_EFFECTS;
  }
}

message GetRepositoryTagRequest {
  // The ID of the repository this tag belongs to.
  string repository_id = 1;
  // The name of the repository tag to get, e.g. "6e2e7f24718a76caa32a80d0e2b1841ef2c61403".
  string name = 2;
}

message GetRepositoryTagResponse {
  RepositoryTag repository_tag = 1;
}

message CreateRepositoryTagRequest {
  // The ID of the repository this tag should be created on.
  string repository_id = 1;
  // The name of the repository tag, e.g. "6e2e7f24718a76caa32a80d0e2b1841ef2c61403".
  string name = 2;
  // The name of the commit this tag should be created for.
  string commit_name = 3;
}

message CreateRepositoryTagResponse {
  RepositoryTag repository_tag = 1;
}

message UpdateRepositoryTagRequest {
  // The ID of the repository this tag belongs to.
  string repository_id = 1;
  // The name of the repository tag, to update e.g. "6e2e7f24718a76caa32a80d0e2b1841ef2c61403".
  string name = 2;
  // The name of the commit this tag should reference.
  optional string commit_name = 3;
}

message UpdateRepositoryTagResponse {
  RepositoryTag repository_tag = 1;
}

message ListRepositoryTagsRequest {
  // The ID of the repository whose tags should be listed.
  string repository_id = 1;
  uint32 page_size = 2;
  // The first page is returned if this is empty.
  string page_token = 3;
  bool reverse = 4;
}

message ListRepositoryTagsResponse {
  repeated RepositoryTag repository_tags = 1;
  // There are no more pages if this is empty.
  string next_page_token = 2;
}

message ListRepositoryTagsForReferenceRequest {
  // The ID of the repository whose tags should be listed.
  string repository_id = 1;
  // Optional reference (if unspecified, will use the repository's default_branch).
  string reference = 2;
  uint32 page_size = 3;
  // The first page is returned if this is empty.
  string page_token = 4;
  bool reverse = 5;
}

message ListRepositoryTagsForReferenceResponse {
  repeated RepositoryTag repository_tags = 1;
  // There are no more pages if this is empty.
  string next_page_token = 2;
}
