syntax = "proto3";
package auth;
import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

option go_package = "com.github/quabynah-bilson/proche;core";

// authentication service for user login, register, reset password, refresh token, logout and etc.
service AuthService {
  // auth
  rpc login (LoginRequest) returns (google.protobuf.StringValue);
  rpc register (RegisterRequest) returns (google.protobuf.StringValue);
  rpc reset_password (ResetPasswordRequest) returns (google.protobuf.StringValue);
  rpc logout (google.protobuf.Empty) returns (google.protobuf.Empty);
  rpc verify_password (google.protobuf.StringValue) returns (google.protobuf.Empty);

  // request public access token for unauthenticated calls
  rpc request_public_access_token (google.protobuf.Empty) returns (google.protobuf.StringValue);

  // validate access token from microservices for authorization (only for internal calls)
  rpc validate_access_token (google.protobuf.Empty) returns (ValidateAccessTokenResponse);

  // account
  rpc get_account (google.protobuf.Empty) returns (Account);
  rpc get_account_by_phone_number (google.protobuf.StringValue) returns (Account);
  rpc get_account_by_id (google.protobuf.StringValue) returns (Account);
  rpc update_account (Account) returns (Account);
  rpc delete_account (google.protobuf.Empty) returns (google.protobuf.Empty);

  // business account
  rpc get_business_account (google.protobuf.StringValue) returns (BusinessAccount);
  rpc update_business_account (BusinessAccount) returns (BusinessAccount);
  rpc delete_business_account (google.protobuf.StringValue) returns (google.protobuf.Empty);
  rpc create_business_account (CreateBusinessAccountRequest) returns (BusinessAccount);

  // referral code
  rpc get_referral_code (google.protobuf.Empty) returns (google.protobuf.StringValue);
  rpc get_referral_code_by_phone_number (google.protobuf.StringValue) returns (google.protobuf.StringValue);

  // country
  rpc get_countries (google.protobuf.Empty) returns (GetCountriesResponse);
  rpc get_country_by_id (google.protobuf.StringValue) returns (Country);
  rpc add_country (Country) returns (Country);
  rpc delete_country (google.protobuf.StringValue) returns (google.protobuf.Empty);
}

message CreateBusinessAccountRequest {
  string account_id = 1;
  string specialization = 2;
  double hourly_rate = 3;
}

message GetCountriesResponse {
  repeated Country countries = 1;
}

// validate access token response message
message ValidateAccessTokenResponse {
  optional string account_id = 1;
  optional string phone_number = 2;
  optional string display_name = 3;
}

// login request message
message LoginRequest {
  string phone_number = 1;
  string password = 2;
  string country_id = 3;
}

// auth response message contains token and refresh token

message RegisterRequest {
  string phone_number = 1;
  string password = 2;
  string display_name = 4;
  optional bytes avatar_url = 5;
  optional string referral_code = 6;
  optional string id_card_url = 7;
  optional string vaccine_card_url = 8;
  string country_id = 9;
}

message ResetPasswordRequest {
  string phone_number = 1;
  string password = 4;
}

message Account {
  string id = 1;
  string phone_number = 2;
  string display_name = 3;
  string language_id = 4;
  google.protobuf.Timestamp created_at = 5;
  google.protobuf.Timestamp updated_at = 6;
  optional string avatar_url = 7;
  optional string id_card_url = 8;
  optional string vaccine_card_url = 9;
  optional string referral_code = 10;
  string country_id = 11;
  optional string device_id = 12;
  optional string device_token = 13;
  optional string device_type = 14;
  optional bool is_verified = 15;
  optional bool is_public_account = 16;
}

message BusinessAccount {
  Account owner = 1;
  string specialization = 2;
  int32 jobs_completed = 3;
  double hourly_rate = 4;
  double ratings = 5;
}

message AccessTokenStore {
  string access_token = 1;
  string refresh_token = 3;
}

message Country {
  string id = 1;
  string name = 2;
  string code = 3;
  string dial_code = 4;
  string currency = 5;
  string currency_symbol = 6;
  string flag_url = 7;
  string language_id = 8;
}