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 (WorkspaceProfile) {
    option (google.api.http) = {get: "/api/v1/workspace/profile"};
  }
  rpc GetWorkspaceSetting(GetWorkspaceSettingRequest) returns (WorkspaceSetting) {
    option (google.api.http) = {get: "/api/v1/workspace/setting"};
  }
  rpc UpdateWorkspaceSetting(UpdateWorkspaceSettingRequest) returns (WorkspaceSetting) {
    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 owner name.
  // Format: "users/{id}"
  string owner = 3;
  // The workspace subscription.
  Subscription subscription = 4;
  // The custom style.
  string custom_style = 5;
  // The workspace branding.
  bytes branding = 6;
}

message WorkspaceSetting {
  // The url of instance.
  string instance_url = 1;
  // The workspace custome branding.
  bytes branding = 2;
  // The custom style.
  string custom_style = 3;
  // The default visibility of shortcuts and collections.
  Visibility default_visibility = 4;
  // The identity providers.
  repeated IdentityProvider identity_providers = 5;
  // Whether to disallow user registration by email&password.
  bool disallow_user_registration = 6;
  // Whether to disallow password authentication.
  bool disallow_password_auth = 7;
}

message IdentityProvider {
  // The unique identifier of the identity provider.
  string id = 1;

  string title = 2;

  enum Type {
    TYPE_UNSPECIFIED = 0;
    OAUTH2 = 1;
  }
  Type type = 3;
  IdentityProviderConfig config = 4;
}

message IdentityProviderConfig {
  oneof config {
    OAuth2Config oauth2 = 1;
  }

  message FieldMapping {
    string identifier = 1;
    string display_name = 2;
  }

  message OAuth2Config {
    string client_id = 1;
    string client_secret = 2;
    string auth_url = 3;
    string token_url = 4;
    string user_info_url = 5;
    repeated string scopes = 6;
    FieldMapping field_mapping = 7;
  }
}

message GetWorkspaceProfileRequest {}

message GetWorkspaceSettingRequest {}

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