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";

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

service RoleService {
        // Creates roles, requires login beforehand.
    // Requires highest permissions.
    rpc CreateRoles(CreateRolesRequest) returns (CreateRolesResponse) {
        option (google.api.http) = {
            post: "/roles/create"
            body: "*"
        };
    }

    // Requests one role with its permissions, requires login beforehand.
    // Requires highest permissions.
    rpc GetRole(GetRoleRequest) returns (GetRoleResponse) {
        option (google.api.http) = {
            get: "/roles/get"
        };
    }

    // Requests all roles with their permissions, requires login beforehand.
    // Requires highest permissions.
    rpc GetRoles(GetRolesRequest) returns (GetRolesResponse) {
        option (google.api.http) = {
            get: "/roles"
        };
    }

    // Updates roles by setting the provided permissions, requires login beforehand.
    // Requires highest permissions.
    rpc UpdateRoles(UpdateRolesRequest) returns (UpdateRolesResponse) {
        option (google.api.http) = {
            post: "/roles/update"
            body: "*"
        };
    }

    // Deletes permissions from given role, requires login beforehand.
    // Requires highest permissions.
    rpc DeletePermissionsForRole(DeletePermissionsForRoleRequest) returns (DeletePermissionsForRoleResponse) {
        option (google.api.http) = {
            delete: "/roles/delete/permissions"
        };
    }

    // Deletes roles with their permissions, requires login beforehand.
    // Requires highest permissions.
    rpc DeleteRoles(DeleteRolesRequest) returns (DeleteRolesResponse) {
        option (google.api.http) = {
            delete: "/roles/delete"
        };
    }
}

message Role {
    string id = 1;
    string name = 2;
    string description = 3;
    repeated string permissions = 4;
}

// CreateRoles
message CreateRolesRequest {
    int64 timestamp = 1;
    repeated Role roles = 2;
}

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

// GetRole
message GetRoleRequest {
    int64 timestamp = 1;
    string role_name = 2;
    string id = 3;
}

message GetRoleResponse {
    int64 timestamp = 1;
    Status status = 2;
    Role role = 3;
}

// GetRoles
message GetRolesRequest {
    int64 timestamp = 1;
}

message GetRolesResponse {
    int64 timestamp = 1;
    Status status = 2;
    repeated Role roles = 3;
}

// UpdateRoles
message UpdateRolesRequest {
    int64 timestamp = 1;
    repeated Role roles = 2;
}

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

// DeletePermissionsForRole
message DeletePermissionsForRoleRequest {
    int64 timestamp = 1;
    string role_name = 2;
    repeated string permissions_to_delete = 3;
}

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

// DeleteRoles
message DeleteRolesRequest {
    int64 timestamp = 1;
    repeated string role_name = 2;
}

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