syntax = "proto3";

package slash.api.v1;

import "api/v1/common.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option go_package = "gen/api/v1";

service CollectionService {
  // ListCollections returns a list of collections.
  rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse) {
    option (google.api.http) = {get: "/api/v1/collections"};
  }
  // GetCollection returns a collection by id.
  rpc GetCollection(GetCollectionRequest) returns (Collection) {
    option (google.api.http) = {get: "/api/v1/collections/{id}"};
    option (google.api.method_signature) = "id";
  }
  // GetCollectionByName returns a collection by name.
  rpc GetCollectionByName(GetCollectionByNameRequest) returns (Collection) {}
  // CreateCollection creates a collection.
  rpc CreateCollection(CreateCollectionRequest) returns (Collection) {
    option (google.api.http) = {
      post: "/api/v1/collections"
      body: "collection"
    };
  }
  // UpdateCollection updates a collection.
  rpc UpdateCollection(UpdateCollectionRequest) returns (Collection) {
    option (google.api.http) = {
      put: "/api/v1/collections/{collection.id}"
      body: "collection"
    };
    option (google.api.method_signature) = "collection,update_mask";
  }
  // DeleteCollection deletes a collection by id.
  rpc DeleteCollection(DeleteCollectionRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/api/v1/collections/{id}"};
    option (google.api.method_signature) = "id";
  }
}

message Collection {
  int32 id = 1;

  int32 creator_id = 2;

  google.protobuf.Timestamp created_time = 3;

  google.protobuf.Timestamp updated_time = 4;

  string name = 6;

  string title = 7;

  string description = 8;

  repeated int32 shortcut_ids = 9;

  Visibility visibility = 10;
}

message ListCollectionsRequest {}

message ListCollectionsResponse {
  repeated Collection collections = 1;
}

message GetCollectionRequest {
  int32 id = 1;
}

message GetCollectionByNameRequest {
  string name = 1;
}

message CreateCollectionRequest {
  Collection collection = 1;
}

message UpdateCollectionRequest {
  Collection collection = 1;

  google.protobuf.FieldMask update_mask = 2;
}

message DeleteCollectionRequest {
  int32 id = 1;
}
