syntax = "proto3";

package gosdn.rbac;

import "google/api/annotations.proto";
import "google/protobuf/descriptor.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

import "gosdn/rbac/rbac.proto";
import "gosdn/conflict/conflict.proto";

option go_package = "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac";

service UserService {
    // Create users with the provided parameters, creation of multiple users requires login beforehand.
    // Highest possible permissions of new users is of current permission level.
    // If not logged in: Created user has lowest possible permissions, only one user can be created this way.
    rpc CreateUsers(CreateUsersRequest) returns (CreateUsersResponse) {
        option (google.api.http) = {
            post: "/users/create"
            body: "*"
        };
    }

    // Requests information about one user, requires login beforehand.option
    rpc GetUser (GetUserRequest) returns (GetUserResponse) {
        option (google.api.http) = {
            get: "/users/get"
        };
    }

    // Requests information about available users, requires login beforehand.
    // Requires highest possible permissions.
    rpc GetUsers (GetUsersRequest) returns (GetUsersResponse) {
        option (google.api.http) = {
            get: "/users"
        };
    }

    // Updates users with the provided parameters, requires login beforehand.
    // Requires highest permissions to change other users, everyone else can only update their own account.
    // Requires highest permissions to change multiple users at the same time.
    rpc UpdateUsers (UpdateUsersRequest) returns (UpdateUsersResponse) {
        option (google.api.http) = {
            post: "/users/update"
            body: "*"
        };
    }

    // Deletes users, requires login beforehand.
    // Requires highest permissions.
    rpc DeleteUsers(DeleteUsersRequest) returns (DeleteUsersResponse) {
        option (google.api.http) = {
            delete: "/users/delete"
        };
    }
}

message User {
    string id = 1;
    string name = 2;
    map<string, string> roles = 3; // Key = pnd uuid, value= role name
    string password = 4;
    string token = 5;
    conflict.Metadata metadata = 6;
}

// CreateUsers
message CreateUsersRequest {
    int64 timestamp = 1;
    repeated User user = 2;
}

message CreateUsersResponse {
    int64 timestamp = 1;
    Status status = 2;
}

// GetUser
message GetUserRequest {
    int64 timestamp = 1;
    string name = 2;
    string id = 3;
}

message GetUserResponse {
    int64 timestamp = 1;
    Status status = 2;
    User user = 3;
}

// GetUsers
message GetUsersRequest {
    int64 timestamp = 1;
}

message GetUsersResponse {
    int64 timestamp = 1;
    Status status = 2;
    repeated User user = 3;
}

// UpdateUsers
message UpdateUsersRequest {
    int64 timestamp = 1;
    repeated User user = 2;
}

message UpdateUsersResponse {
    int64 timestamp = 1;
    Status status = 2;
}

// DeleteUsers
message DeleteUsersRequest {
    int64 timestamp = 1;
    repeated string username = 2;
}

message DeleteUsersResponse {
    int64 timestamp = 1;
    Status status = 2;
}
