syntax = "proto3";

package memos.api.v2;

import "google/api/annotations.proto";

option go_package = "gen/api/v2";

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

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

message UpsertTagRequest {
  string name = 1;
}

message UpsertTagResponse {
  Tag tag = 1;
}

message BatchUpsertTagRequest {
  repeated UpsertTagRequest requests = 1;
}

message BatchUpsertTagResponse {}

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 RenameTagResponse {
  Tag tag = 1;
}

message DeleteTagRequest {
  Tag tag = 1;
}

message DeleteTagResponse {}

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

message GetTagSuggestionsResponse {
  repeated string tags = 1;
}
