syntax = "proto3";

package slash.api.v1;

import "api/v1/common.proto";
import "api/v1/subscription_service.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/field_mask.proto";

option go_package = "gen/api/v1";

service WorkspaceService {
  rpc GetWorkspaceProfile(GetWorkspaceProfileRequest) returns (GetWorkspaceProfileResponse) {
    option (google.api.http) = {get: "/api/v1/workspace/profile"};
  }
  rpc GetWorkspaceSetting(GetWorkspaceSettingRequest) returns (GetWorkspaceSettingResponse) {
    option (google.api.http) = {get: "/api/v1/workspace/setting"};
  }
  rpc UpdateWorkspaceSetting(UpdateWorkspaceSettingRequest) returns (UpdateWorkspaceSettingResponse) {
    option (google.api.http) = {
      patch: "/api/v1/workspace/setting"
      body: "setting"
    };
    option (google.api.method_signature) = "setting,update_mask";
  }
}

message WorkspaceProfile {
  // Current workspace mode: dev, prod.
  string mode = 1;
  // Current workspace version.
  string version = 2;
  // The workspace plan.
  PlanType plan = 3;
  // Whether to enable other users to sign up.
  bool enable_signup = 4;
  // The custom style.
  string custom_style = 5;
  // The custom script.
  string custom_script = 6;
  // The url of custom favicon provider.
  string favicon_provider = 7;
  // The owner name.
  // Format: "users/{id}"
  string owner = 8;
}

message WorkspaceSetting {
  string license_key = 1;
  // Whether to enable other users to sign up.
  bool enable_signup = 2;
  // The instance URL.
  string instance_url = 3;
  // The custom style.
  string custom_style = 4;
  // The custom script.
  string custom_script = 5;
  // The auto backup setting. (Unimplemented)
  AutoBackupWorkspaceSetting auto_backup = 6;
  // The default visibility of shortcuts and collections.
  Visibility default_visibility = 7;
  // The url of custom favicon provider.
  string favicon_provider = 8;
}

message AutoBackupWorkspaceSetting {
  // Whether auto backup is enabled.
  bool enabled = 1;
  // The cron expression for auto backup.
  // For example, "0 0 0 * * *" means backup at 00:00:00 every day.
  // See https://en.wikipedia.org/wiki/Cron for more details.
  string cron_expression = 2;
  // The maximum number of backups to keep.
  int32 max_keep = 3;
}

message GetWorkspaceProfileRequest {}

message GetWorkspaceProfileResponse {
  // The workspace profile.
  WorkspaceProfile profile = 1;
}

message GetWorkspaceSettingRequest {}

message GetWorkspaceSettingResponse {
  // The user setting.
  WorkspaceSetting setting = 1;
}

message UpdateWorkspaceSettingRequest {
  // The user setting.
  WorkspaceSetting setting = 1;
  // The update mask.
  google.protobuf.FieldMask update_mask = 2;
}

message UpdateWorkspaceSettingResponse {
  // The user setting.
  WorkspaceSetting setting = 1;
}
