syntax = "proto3";

package ocis.services.settings.v0;

option go_package = "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v0";

import "ocis/messages/settings/v0/settings.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  info: {
    title: "ownCloud Infinite Scale settings";
    version: "1.0.0";
    contact: {
      name: "ownCloud GmbH";
      url: "https://github.com/owncloud/ocis";
      email: "support@owncloud.com";
    };
    license: {
      name: "Apache-2.0";
      url: "https://github.com/owncloud/ocis/blob/master/LICENSE";
    };
  };
  schemes: HTTP;
  schemes: HTTPS;
  consumes: "application/json";
  produces: "application/json";
  external_docs: {
    description: "Developer Manual";
    url: "https://owncloud.dev/extensions/settings/";
  };
};

service BundleService {
  rpc SaveBundle(SaveBundleRequest) returns (SaveBundleResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/bundle-save",
      body: "*"
    };
  }
  rpc GetBundle(GetBundleRequest) returns (GetBundleResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/bundle-get",
      body: "*"
    };
  }
  rpc ListBundles(ListBundlesRequest) returns (ListBundlesResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/bundles-list",
      body: "*"
    };
  }
  rpc AddSettingToBundle(AddSettingToBundleRequest) returns (AddSettingToBundleResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/bundles-add-setting",
      body: "*"
    };
  }
  rpc RemoveSettingFromBundle(RemoveSettingFromBundleRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/api/v0/settings/bundles-remove-setting",
      body: "*"
    };
  }
}

service ValueService {
  rpc SaveValue(SaveValueRequest) returns (SaveValueResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/values-save",
      body: "*"
    };
  }
  rpc GetValue(GetValueRequest) returns (GetValueResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/values-get",
      body: "*"
    };
  }
  rpc ListValues(ListValuesRequest) returns (ListValuesResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/values-list",
      body: "*"
    };
  }
  rpc GetValueByUniqueIdentifiers(GetValueByUniqueIdentifiersRequest) returns (GetValueResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/values-get-by-unique-identifiers",
      body: "*"
    };
  }
}

service RoleService {
  rpc ListRoles(ListBundlesRequest) returns (ListBundlesResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/roles-list",
      body: "*"
    };
  }
  rpc ListRoleAssignments(ListRoleAssignmentsRequest) returns (ListRoleAssignmentsResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/assignments-list",
      body: "*"
    };
  }
  rpc AssignRoleToUser(AssignRoleToUserRequest) returns (AssignRoleToUserResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/assignments-add",
      body: "*"
    };
  }
  rpc RemoveRoleFromUser(RemoveRoleFromUserRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/api/v0/settings/assignments-remove",
      body: "*"
    };
  }
}

service PermissionService {
  rpc ListPermissionsByResource(ListPermissionsByResourceRequest) returns (ListPermissionsByResourceResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/permissions-list-by-resource",
      body: "*"
    };
  }
  rpc GetPermissionByID(GetPermissionByIDRequest) returns (GetPermissionByIDResponse) {
    option (google.api.http) = {
      post: "/api/v0/settings/permissions-get-by-id",
      body: "*"
    };
  }
}

// ---
// requests and responses for settings bundles
// ---
message SaveBundleRequest {
  ocis.messages.settings.v0.Bundle bundle = 1;
}

message SaveBundleResponse {
  ocis.messages.settings.v0.Bundle bundle = 1;
}

message GetBundleRequest {
  string bundle_id = 1;
}

message GetBundleResponse {
  ocis.messages.settings.v0.Bundle bundle = 1;
}

message ListBundlesRequest {
  repeated string bundle_ids = 1;
}

message ListBundlesResponse {
  repeated ocis.messages.settings.v0.Bundle bundles = 1;
}

message AddSettingToBundleRequest {
  string bundle_id = 1;
  ocis.messages.settings.v0.Setting setting = 2;
}

message AddSettingToBundleResponse {
  ocis.messages.settings.v0.Setting setting = 1;
}

message RemoveSettingFromBundleRequest {
  string bundle_id = 1;
  string setting_id = 2;
}

// ---
// requests and responses for settings values
// ---

message SaveValueRequest {
  ocis.messages.settings.v0.Value value = 1;
}

message SaveValueResponse {
  ocis.messages.settings.v0.ValueWithIdentifier value = 1;
}

message GetValueRequest {
  string id = 1;
}

message GetValueResponse {
  ocis.messages.settings.v0.ValueWithIdentifier value = 1;
}

message ListValuesRequest {
  string bundle_id = 1;
  string account_uuid = 2;
}

message ListValuesResponse {
  repeated ocis.messages.settings.v0.ValueWithIdentifier values = 1;
}

message GetValueByUniqueIdentifiersRequest{
  string account_uuid = 1;
  string setting_id = 2;
}

// --
// requests and responses for role assignments
// ---

message ListRoleAssignmentsRequest {
  string account_uuid = 1;
}

message ListRoleAssignmentsResponse {
  repeated ocis.messages.settings.v0.UserRoleAssignment assignments = 1;
}

message AssignRoleToUserRequest {
  string account_uuid = 1;
  // the role_id is a bundle_id internally
  string role_id = 2;
}

message AssignRoleToUserResponse {
  ocis.messages.settings.v0.UserRoleAssignment assignment = 1;
}

message RemoveRoleFromUserRequest {
  string id = 1;
}

// --
// requests and responses for permissions
// ---

message ListPermissionsByResourceRequest {
  ocis.messages.settings.v0.Resource resource = 1;
}

message ListPermissionsByResourceResponse {
  repeated ocis.messages.settings.v0.Permission permissions = 1;
}

message GetPermissionByIDRequest {
  string permission_id = 1;
}

message GetPermissionByIDResponse {
  ocis.messages.settings.v0.Permission permission = 1;
}
