syntax = "proto3";

package svc.token.v1;

import "google/protobuf/timestamp.proto";
import "types/v1/cursor.proto";
import "types/v1/environment_token.proto";

option go_package = "svc/token/v1;tokenv1";

service TokenService {
  rpc GenerateEnvironmentToken(GenerateEnvironmentTokenRequest) returns (GenerateEnvironmentTokenResponse) {}
  rpc RevokeEnvironmentToken(RevokeEnvironmentTokenRequest) returns (RevokeEnvironmentTokenResponse) {}
  rpc GetEnvironmentToken(GetEnvironmentTokenRequest) returns (GetEnvironmentTokenResponse) {}
  rpc ListEnvironmentToken(ListEnvironmentTokenRequest) returns (ListEnvironmentTokenResponse) {}
}

message GenerateEnvironmentTokenRequest {
  int64 environment_id = 1;
  google.protobuf.Timestamp expires_at = 2;
  repeated types.v1.EnvironmentRole roles = 3;
}

message GenerateEnvironmentTokenResponse {
  types.v1.EnvironmentToken token = 1;
}

message RevokeEnvironmentTokenRequest {
  int64 environment_id = 1;
  int64 token_id = 2;
}

message RevokeEnvironmentTokenResponse {}

message GetEnvironmentTokenRequest {
  int64 environment_id = 1;
  int64 token_id = 2;
}

message GetEnvironmentTokenResponse {
  types.v1.EnvironmentToken token = 1;
}

message ListEnvironmentTokenRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
  int64 environment_id = 3;
}

message ListEnvironmentTokenResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.EnvironmentToken token = 1;
  }
  repeated ListItem items = 2;
}
