// SPDX-License-Identifier: Apache-2.0
// Multi-tenant self-service (docs/cloud/SELF_SERVICE.md §2, §3, §5): tenants, their
// quotas, users, servers and monthly usage. Bodies travel as JSON in the schemas of the
// REST API (`/v1/tenants`, docs/api/openapi.yaml); the rules are the REST rules.
syntax = "proto3";

package kyvernon.v1;

import "kyvernon/v1/common.proto";

// Tenants of a self-service portal and their servers. Bodies are JSON in the shape of the REST API.
service TenantService {
  // TenantView[] (Kyvernon.Tenant.Read on the root).
  rpc ListTenants(Empty) returns (JsonBody);
  // TenantView.
  rpc GetTenant(TenantRequest) returns (JsonBody);
  // CreateTenantRequest -> TenantView.
  rpc CreateTenant(JsonBody) returns (JsonBody);
  // QuotaView -> TenantView.
  rpc SetQuota(TenantJsonRequest) returns (JsonBody);
  // Suspends a tenant: its virtual machines shut down and its users become read-only.
  rpc SuspendTenant(TenantRequest) returns (TaskRef);
  // Resumes a suspended tenant and starts the virtual machines that ran.
  rpc ResumeTenant(TenantRequest) returns (TaskRef);
  // CloseTenantRequest.
  rpc CloseTenant(TenantJsonRequest) returns (TaskRef);
  // TenantUsageView of `month` (YYYY-MM, empty: current).
  rpc GetUsage(UsageRequest) returns (JsonBody);
  // ServerView[].
  rpc ListServers(TenantRequest) returns (JsonBody);
  // ServerView.
  rpc GetServer(ServerRequest) returns (JsonBody);
  // CreateServerRequest -> ServerTaskView (with the generated password, once).
  rpc CreateServer(TenantJsonRequest) returns (JsonBody);
  // One server operation -> ServerTaskView (console: ConsoleTicketView).
  rpc ServerAction(ServerActionRequest) returns (JsonBody);
}

// A JSON document.
message JsonBody {
  // The body as JSON, in the shape of the REST API.
  string json = 1;
}

// Names a tenant.
message TenantRequest {
  // Id of the tenant.
  string tenant = 1;
}

// A tenant and a JSON body.
message TenantJsonRequest {
  // Id of the tenant.
  string tenant = 1;
  // The body as JSON, in the shape of the REST API.
  string json = 2;
}

// Usage of a tenant in a month.
message UsageRequest {
  // Id of the tenant.
  string tenant = 1;
  // `YYYY-MM`; empty for the current month.
  string month = 2;
}

// Names a server of a tenant.
message ServerRequest {
  // Id of the tenant.
  string tenant = 1;
  // Id of the server.
  string server = 2;
}

// One operation on a server.
message ServerActionRequest {
  // Id of the tenant.
  string tenant = 1;
  // Id of the server.
  string server = 2;
  // delete, power (json: ServerPowerRequest), reinstall (ReinstallServerRequest), resize
  // (ResizeServerRequest), rescue (RescueServerRequest), unrescue, reset-password,
  // snapshot (ServerSnapshotRequest), remove-snapshot, revert-snapshot, console.
  string action = 3;
  // The operation as JSON, in the shape of the REST API.
  string json = 4;
  // Snapshot key of remove-snapshot and revert-snapshot.
  uint32 snapshot = 5;
}
