// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package token.v1;
option go_package = "github.com/absmach/magistrala/api/grpc/token/v1";

service TokenService {
  rpc Issue(IssueReq) returns (Token) {}
  rpc Refresh(RefreshReq) returns (Token) {}
  rpc Revoke(RevokeReq) returns (RevokeRes) {}
  rpc ListUserRefreshTokens(ListUserRefreshTokensReq) 
  returns (ListUserRefreshTokensRes) {}
}

message IssueReq {
  string user_id = 1;
  uint32 user_role = 2;
  uint32 type = 3;
  bool verified = 4;
  string description = 5;
}

message RefreshReq {
  string refresh_token = 1;
  bool verified = 2;
}

message RevokeReq {
  string token_id = 1;
  string user_id = 2;
}

// If a token is not carrying any information itself, the type
// field can be used to determine how to validate the token.
// Also, different tokens can be encoded in different ways.
message Token {
  string access_token = 1;
  optional string refresh_token = 2;
  string access_type = 3;
}

message RevokeRes{

}

message ListUserRefreshTokensReq {
  string user_id = 1;
}

message ListUserRefreshTokensRes {
  repeated RefreshToken refresh_tokens = 1;
}

message RefreshToken {
  string id = 1;
  string description = 2;
}
