syntax = "proto3";

package memos.api.v2;

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

option go_package = "gen/api/v2";

service ResourceService {
  rpc CreateResource(CreateResourceRequest) returns (CreateResourceResponse) {
    option (google.api.http) = {post: "/api/v2/resources"};
  }
  rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse) {
    option (google.api.http) = {get: "/api/v2/resources"};
  }
  rpc UpdateResource(UpdateResourceRequest) returns (UpdateResourceResponse) {
    option (google.api.http) = {put: "/api/v2/resources/{id}"};
    option (google.api.method_signature) = "id";
  }
  rpc DeleteResource(DeleteResourceRequest) returns (DeleteResourceResponse) {
    option (google.api.http) = {get: "/api/v2/resources/{id}"};
    option (google.api.method_signature) = "id";
  }
}

message Resource {
  int32 id = 1;
  google.protobuf.Timestamp created_ts = 2;
  string filename = 3;
  string external_link = 4;
  string type = 5;
  int64 size = 6;
  optional int32 memo_id = 7;
}

message CreateResourceRequest {
  string filename = 1;
  string external_link = 2;
  string type = 3;
  optional int32 memo_id = 4;
}

message CreateResourceResponse {
  Resource resource = 1;
}

message ListResourcesRequest {}

message ListResourcesResponse {
  repeated Resource resources = 1;
}

message UpdateResourceRequest {
  int32 id = 1;

  Resource resource = 2;

  repeated string update_mask = 3;
}

message UpdateResourceResponse {
  Resource resource = 1;
}

message DeleteResourceRequest {
  int32 id = 1;
}

message DeleteResourceResponse {}
