syntax = "proto3";

package svc.user.v1;

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

option go_package = "svc/user/v1;userv1";

service UserService {
  rpc Whoami(WhoamiRequest) returns (WhoamiResponse) {}
  rpc GetLogoutURL(GetLogoutURLRequest) returns (GetLogoutURLResponse) {}
  rpc RefreshUserToken(RefreshUserTokenRequest) returns (RefreshUserTokenResponse) {}

  rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse) {}

  rpc CreateOrganization(CreateOrganizationRequest) returns (CreateOrganizationResponse) {}
  rpc ListOrganization(ListOrganizationRequest) returns (ListOrganizationResponse) {}
}

message WhoamiRequest {}
message WhoamiResponse {
  types.v1.User user = 1;
  types.v1.Organization current_organization = 2;
  types.v1.Organization default_organization = 3;
}

message GetLogoutURLRequest {
  string return_to = 1;
}

message GetLogoutURLResponse {
  string logout_url = 1;
}

message RefreshUserTokenRequest {}

message RefreshUserTokenResponse {
  string token = 1;
  google.protobuf.Timestamp refresh_at = 2;
  google.protobuf.Timestamp expires_at = 3;
}

message UpdateUserRequest {
  optional string first_name = 1;
  optional string last_name = 2;
}
message UpdateUserResponse {
  types.v1.User user = 1;
}

message CreateOrganizationRequest {
  string name = 1;
}

message CreateOrganizationResponse {
  types.v1.Organization organization = 1;
}

message ListOrganizationRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
}

message ListOrganizationResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.Organization organization = 1;
  }
  repeated ListItem items = 2;
  types.v1.Organization default_organization = 3;
}
