syntax = "proto3";
package user;
import "google/protobuf/empty.proto";

service User {
  // Create new user
  rpc CreateUser(NewUserObj) returns (UserObj);
  // Get all user (as stream)
  rpc GetAll(google.protobuf.Empty) returns (stream UserObj);
  // Get user by id
  rpc GetById(GetByIdRequest) returns (UserObj);
  // Update user by id
  rpc UpdateById(UserObj) returns (UserObj);
  // Reset user password
  rpc ResetPassword(ResetPasswordRequest) returns (ResetPasswordResponse);
  // Set new password
  rpc SetNewPassword(NewPasswordRequest) returns (NewPasswordResponse);
  // Login
  rpc Login(LoginRequest) returns (UserObj);
}

message LoginRequest {
  string username = 1;
  string password = 2;
}

message LoginResponse {
  bool is_valid = 1;
  UserObj user = 3;
}

message NewPasswordRequest {
  uint32 uid = 1;
  string new_password = 2;
}

message NewPasswordResponse {}

message ResetPasswordRequest { string email = 1; }

message ResetPasswordResponse {}

message AllUserRequest {}

message UserObj {
  uint32 uid = 1;
  string username = 2;
  string name = 3;
  string email = 4;
  string phone = 5;
  uint32 created_by = 6; // UID
  string created_at = 7; // RFC3339
}

message NewUserObj {
  string username = 1;
  string name = 3;
  string email = 2;
  string phone = 4;
  uint32 created_by = 5;
}

message GetByIdRequest { uint32 userid = 1; }