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);
  // Validate login request
  rpc ValidateLogin(LoginRequest) returns (LoginResponse);
}

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

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

message NewPasswordRequest {
  string userid = 1;
  string new_password = 2;
}

message NewPasswordResponse {}

message ResetPasswordRequest { string email = 1; }

message ResetPasswordResponse {}

message AllUserRequest {}

message UserObj {
  string id = 1;
  string name = 2;
  string email = 3;
  string phone = 4;
  repeated string customers = 5; // This will be Vec<String>
  string created_by = 6;
  string created_at = 7; // maybe datetime type?
}

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

message GetByIdRequest { string userid = 1; }