syntax = "proto3";

package memos.api.v2;

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

option go_package = "gen/api/v2";

service ResourceService {
  // CreateResource creates a new resource.
  rpc CreateResource(CreateResourceRequest) returns (CreateResourceResponse) {
    option (google.api.http) = {post: "/api/v2/resources"};
  }
  // ListResources lists all resources.
  rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse) {
    option (google.api.http) = {get: "/api/v2/resources"};
  }
  // SearchResources searches memos.
  rpc SearchResources(SearchResourcesRequest) returns (SearchResourcesResponse) {
    option (google.api.http) = {get: "/api/v2/resources:search"};
  }
  // GetResource returns a resource by name.
  rpc GetResource(GetResourceRequest) returns (GetResourceResponse) {
    option (google.api.http) = {get: "/api/v2/{name=resources/*}"};
    option (google.api.method_signature) = "name";
  }
  // UpdateResource updates a resource.
  rpc UpdateResource(UpdateResourceRequest) returns (UpdateResourceResponse) {
    option (google.api.http) = {
      patch: "/api/v2/{resource.name=resources/*}",
      body: "resource"
    };
    option (google.api.method_signature) = "resource,update_mask";
  }
  // DeleteResource deletes a resource by name.
  rpc DeleteResource(DeleteResourceRequest) returns (DeleteResourceResponse) {
    option (google.api.http) = {delete: "/api/v2/{name=resources/*}"};
    option (google.api.method_signature) = "name";
  }
}

message Resource {
  // The name of the resource.
  // Format: resources/{id}
  // id is the system generated unique identifier.
  string name = 1;

  // The user defined id of the resource.
  string uid = 2;

  google.protobuf.Timestamp create_time = 3;

  string filename = 4;

  string external_link = 5;

  string type = 6;

  int64 size = 7;

  // Format: memos/{id}
  optional string memo = 8;
}

message CreateResourceRequest {
  string filename = 1;

  string external_link = 2;

  string type = 3;

  // Format: memos/{id}
  optional string memo = 4;
}

message CreateResourceResponse {
  Resource resource = 1;
}

message ListResourcesRequest {}

message ListResourcesResponse {
  repeated Resource resources = 1;
}

message SearchResourcesRequest {
  string filter = 1;
}

message SearchResourcesResponse {
  repeated Resource resources = 1;
}

message GetResourceRequest {
  string name = 1;
}

message GetResourceResponse {
  Resource resource = 1;
}

message UpdateResourceRequest {
  Resource resource = 1;

  google.protobuf.FieldMask update_mask = 2;
}

message UpdateResourceResponse {
  Resource resource = 1;
}

message DeleteResourceRequest {
  string name = 1;
}

message DeleteResourceResponse {}
