syntax = "proto3";

package nominal.file_store.v1;

import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "nominal/protos/file_store/v1/file_store.proto";
import "nominal/protos/gen/v1/alias.proto";

option java_multiple_files = true;
option java_package = "io.nominal.file_store.v1";

// Manages File Store drives.
service InternalDrivesService {
  // Creates a managed drive.
  rpc CreateDrive(CreateDriveRequest) returns (CreateDriveResponse) {
    option (google.api.http) = {
      post: "/file-store/v1/drives"
      body: "*"
    };
  }

  // Creates a virtual drive.
  rpc CreateVirtualDrive(CreateVirtualDriveRequest) returns (CreateVirtualDriveResponse) {
    option (google.api.http) = {
      post: "/file-store/v1/virtual-drives"
      body: "*"
    };
  }

  // Gets a drive by RID.
  rpc GetDrive(GetDriveRequest) returns (GetDriveResponse) {
    option (google.api.http) = {get: "/file-store/v1/drives/{drive_rid}"};
  }

  // Gets a virtual drive by RID.
  rpc GetVirtualDrive(GetVirtualDriveRequest) returns (GetVirtualDriveResponse) {
    option (google.api.http) = {get: "/file-store/v1/virtual-drives/{drive_rid}"};
  }

  // Gets a drive by name within a workspace.
  rpc GetDriveByName(GetDriveByNameRequest) returns (GetDriveByNameResponse) {
    option (google.api.http) = {get: "/file-store/v1/workspaces/{workspace_rid}/drives/{name}"};
  }

  // Gets a virtual drive by name within a workspace.
  rpc GetVirtualDriveByName(GetVirtualDriveByNameRequest) returns (GetVirtualDriveByNameResponse) {
    option (google.api.http) = {get: "/file-store/v1/workspaces/{workspace_rid}/virtual-drives/{name}"};
  }

  // Lists drives in a workspace.
  rpc ListDrives(ListDrivesRequest) returns (ListDrivesResponse) {
    option (google.api.http) = {get: "/file-store/v1/workspaces/{workspace_rid}/drives"};
  }

  // Updates a virtual drive.
  rpc UpdateVirtualDrive(UpdateVirtualDriveRequest) returns (UpdateVirtualDriveResponse) {
    option (google.api.http) = {
      put: "/file-store/v1/virtual-drives/{drive_rid}"
      body: "*"
    };
  }

  // Currently admin-only: renames a drive.
  rpc RenameDrive(RenameDriveRequest) returns (RenameDriveResponse) {
    option (google.api.http) = {
      post: "/file-store/v1/drives/{drive_rid}/rename"
      body: "*"
    };
  }

  // Currently admin-only: archives a drive.
  rpc ArchiveDrive(ArchiveDriveRequest) returns (ArchiveDriveResponse) {
    option (google.api.http) = {
      post: "/file-store/v1/drives/{drive_rid}/archive"
      body: "*"
    };
  }

  // Currently admin-only: unarchives a drive.
  rpc UnarchiveDrive(UnarchiveDriveRequest) returns (UnarchiveDriveResponse) {
    option (google.api.http) = {
      post: "/file-store/v1/drives/{drive_rid}/unarchive"
      body: "*"
    };
  }
}

message CreateDriveRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  string name = 2 [(buf.validate.field).string = {pattern: "^[a-z0-9][a-z0-9_-]*$"}];
}

message CreateDriveResponse {
  Drive drive = 1;
}

message CreateVirtualDriveRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  string name = 2 [(buf.validate.field).string = {pattern: "^[a-z0-9][a-z0-9_-]*$"}];
  // Provider-specific connection details. Secret fields reference Secrets Service values.
  VirtualDriveConnectionDetails connection_details = 3;
}

message CreateVirtualDriveResponse {
  Drive drive = 1;
  VirtualDrive virtual_drive = 2;
}

message GetDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
}

message GetDriveResponse {
  Drive drive = 1;
}

message GetVirtualDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
}

message GetVirtualDriveResponse {
  Drive drive = 1;
  VirtualDrive virtual_drive = 2;
}

message GetDriveByNameRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  string name = 2;
}

message GetDriveByNameResponse {
  Drive drive = 1;
}

message GetVirtualDriveByNameRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  string name = 2;
}

message GetVirtualDriveByNameResponse {
  Drive drive = 1;
  VirtualDrive virtual_drive = 2;
}

message ListDrivesRequest {
  string workspace_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"}];
  bool include_archived = 2;
  optional int32 page_size = 3;
  optional string page_token = 4 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.Token"}];
}

message ListDrivesResponse {
  repeated Drive drives = 1;
  optional string next_page_token = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.Token"}];
}

message UpdateVirtualDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
  // Provider-specific connection details. Secret fields reference Secrets Service values.
  VirtualDriveConnectionDetails connection_details = 2;
}

message UpdateVirtualDriveResponse {
  Drive drive = 1;
  VirtualDrive virtual_drive = 2;
}

message RenameDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
  string name = 2 [(buf.validate.field).string = {pattern: "^[a-z0-9][a-z0-9_-]*$"}];
}

message RenameDriveResponse {
  Drive drive = 1;
}

message ArchiveDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
}

message ArchiveDriveResponse {
  Drive drive = 1;
}

message UnarchiveDriveRequest {
  string drive_rid = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DriveRid"}];
}

message UnarchiveDriveResponse {
  Drive drive = 1;
}
