syntax = "proto3";

package fricon.v1alpha;

import "google/protobuf/timestamp.proto";

// Dataset status enum
enum DatasetStatus {
  DATASET_STATUS_UNSPECIFIED = 0;
  DATASET_STATUS_WRITING = 1;
  DATASET_STATUS_COMPLETED = 2;
  DATASET_STATUS_ABORTED = 3;
}

// Manage datasets.
service DatasetService {
  // Create a new dataset.
  rpc Create(stream CreateRequest) returns (CreateResponse) {}
  // Get a dataset in the workspace.
  rpc Get(GetRequest) returns (GetResponse) {}
  // Add tags to a dataset.
  rpc AddTags(AddTagsRequest) returns (AddTagsResponse) {}
  // Remove tags from a dataset.
  rpc RemoveTags(RemoveTagsRequest) returns (RemoveTagsResponse) {}
  // Update metadata of a dataset.
  rpc Update(UpdateRequest) returns (UpdateResponse) {}
  // Delete a dataset.
  rpc Delete(DeleteRequest) returns (DeleteResponse) {}
  // List datasets in the workspace.
  rpc Search(SearchRequest) returns (SearchResponse) {}
}

message CreateRequest {
  // The streaming sequence for CreateRequest:
  // 1. The client must first send a CreateMetadata message to initiate dataset creation.
  // 2. The client can then send one or more payload messages containing dataset data.
  // 3. The client must end the stream with either CreateFinish or CreateAbort.
  // If the stream is closed without a terminal message, the creation is considered aborted.
  // Only one of these fields should be set per message.
  oneof create_message {
    CreateMetadata metadata = 1;
    bytes payload = 2;
    CreateAbort abort = 3;
    CreateFinish finish = 4;
  }
}

message CreateMetadata {
  string name = 1;
  string description = 2;
  repeated string tags = 3;
}

message CreateAbort {}

message CreateFinish {}

message CreateResponse {
  Dataset dataset = 1;
}

message GetRequest {
  oneof id_enum {
    int32 id = 1;
    string uid = 2;
  }
}

message GetResponse {
  Dataset dataset = 1;
}

message AddTagsRequest {
  int32 id = 1;
  repeated string tags = 2;
}

message AddTagsResponse {}

message RemoveTagsRequest {
  int32 id = 1;
  repeated string tags = 2;
}

message RemoveTagsResponse {}

message UpdateRequest {
  int32 id = 1;
  optional string name = 2;
  optional string description = 3;
  optional bool favorite = 4;
}

message UpdateResponse {}

message DeleteRequest {
  int32 id = 1;
}

message DeleteResponse {}

message SearchRequest {
  int32 page_size = 1;
  string page_token = 2;
}

message SearchResponse {
  repeated Dataset datasets = 1;
  string next_page_token = 2;
}

message Dataset {
  int32 id = 1;
  DatasetMetadata metadata = 2;
}

message DatasetMetadata {
  string uid = 1;
  string name = 2;
  string description = 3;
  bool favorite = 4;
  google.protobuf.Timestamp created_at = 5;
  repeated string tags = 6;
  DatasetStatus status = 7;
  optional google.protobuf.Timestamp trashed_at = 8;
  optional google.protobuf.Timestamp deleted_at = 9;
}
