syntax = "proto3";

package memos.api.v1;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

option go_package = "gen/api/v1";

service TagService {
  // UpsertTag upserts a tag.
  rpc UpsertTag(UpsertTagRequest) returns (Tag) {
    option (google.api.http) = {
      post: "/api/v1/tags",
      body: "*"
    };
  }
  // BatchUpsertTag upserts multiple tags.
  rpc BatchUpsertTag(BatchUpsertTagRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/api/v1/tags:batchUpsert",
      body: "*"
    };
  }
  // ListTags lists tags.
  rpc ListTags(ListTagsRequest) returns (ListTagsResponse) {
    option (google.api.http) = {get: "/api/v1/tags"};
  }
  // RenameTag renames a tag.
  // All related memos will be updated.
  rpc RenameTag(RenameTagRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      patch: "/api/v1/tags:rename",
      body: "*"
    };
  }
  // DeleteTag deletes a tag.
  rpc DeleteTag(DeleteTagRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/api/v1/tags"};
  }
  // GetTagSuggestions gets tag suggestions from the user's memos.
  rpc GetTagSuggestions(GetTagSuggestionsRequest) returns (GetTagSuggestionsResponse) {
    option (google.api.http) = {get: "/api/v1/tags/suggestion"};
  }
}

message Tag {
  string name = 1;
  // The creator of tags.
  // Format: users/{id}
  string creator = 2;
}

message UpsertTagRequest {
  string name = 1;
}

message BatchUpsertTagRequest {
  repeated UpsertTagRequest requests = 1;
}

message ListTagsRequest {}

message ListTagsResponse {
  repeated Tag tags = 1;
}

message RenameTagRequest {
  // The creator of tags.
  // Format: users/{id}
  string user = 1;
  string old_name = 2;
  string new_name = 3;
}

message DeleteTagRequest {
  Tag tag = 1;
}

message GetTagSuggestionsRequest {
  // The creator of tags.
  // Format: users/{id}
  string user = 1;
}

message GetTagSuggestionsResponse {
  repeated string tags = 1;
}
