syntax = "proto3";

package user;

option go_package = "github.com/echofi-ai/schema/v2/types/user";

import "user/user.proto";

// UserService defines the gRPC service for user operations
service UserService {
  // GetUser retrieves a user by ID
  rpc GetUser(GetUserRequest) returns (GetUserResponse) {}

  // UpdateUser updates user metadata (name, image, etc.)
  rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse) {}

  // ListUsers retrieves users with pagination
  rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) {}

  // Account Linking Operations

  // CheckWalletLinking checks if a wallet can be linked to the current user
  rpc CheckWalletLinking(CheckWalletLinkingRequest) returns (CheckWalletLinkingResponse) {}

  // LinkWalletToUser links a wallet address to the authenticated user
  rpc LinkWalletToUser(LinkWalletToUserRequest) returns (LinkWalletToUserResponse) {}

  // CheckEmailLinking checks if an email can be linked to the current user
  rpc CheckEmailLinking(CheckEmailLinkingRequest) returns (CheckEmailLinkingResponse) {}

  // LinkEmailToUser links an email/password to the authenticated user
  rpc LinkEmailToUser(LinkEmailToUserRequest) returns (LinkEmailToUserResponse) {}

  // GetUserAuthState gets the current authentication state of a user
  rpc GetUserAuthState(GetUserAuthStateRequest) returns (GetUserAuthStateResponse) {}


}

// GetUserRequest is the request message for getting a user
message GetUserRequest {
  // User ID (optional - defaults to authenticated user)
  optional string id = 1;
}

// GetUserResponse is the response message for getting a user
message GetUserResponse {
  // User data
  User user = 1;
}

// UpdateUserRequest is the request message for updating user metadata
message UpdateUserRequest {
  // User ID (optional - defaults to authenticated user)
  optional string id = 1;

  // User name (optional)
  optional string name = 2;

  // User profile image URL (optional)
  optional string image = 3;

  // User background (optional)
  optional string background = 4;

  // Username (optional, unique)
  optional string username = 5;
}

// UpdateUserResponse is the response message for updating a user
message UpdateUserResponse {
  // Updated user data
  User user = 1;

  // Success message
  string message = 2;
}

// ListUsersRequest is the request message for listing users
message ListUsersRequest {
  // Offset for pagination
  int32 offset = 1;
  
  // Limit for pagination (max 100)
  int32 limit = 2;
}

// ListUsersResponse is the response message for listing users
message ListUsersResponse {
  // List of users
  repeated User users = 1;

  // Total count of users
  int64 total = 2;

  // Current offset
  int32 offset = 3;

  // Current limit
  int32 limit = 4;
}

// Account Linking Messages

// CheckWalletLinkingRequest checks if a wallet can be linked
message CheckWalletLinkingRequest {
  // Wallet address to check
  string wallet_address = 1;
}

// CheckWalletLinkingResponse returns wallet linking validation result
message CheckWalletLinkingResponse {
  // Whether the wallet can be linked
  bool can_link = 1;

  // Error message if cannot link
  optional string error = 2;

  // Existing user info if wallet is already linked
  optional ExistingUserInfo existing_user = 3;
}

// LinkWalletToUserRequest links a wallet to the authenticated user
message LinkWalletToUserRequest {
  // Wallet address to link
  string wallet_address = 1;
}

// LinkWalletToUserResponse returns the result of wallet linking
message LinkWalletToUserResponse {
  // Success indicator
  bool success = 1;

  // Success message
  string message = 2;

  // Updated user data
  User user = 3;
}

// CheckEmailLinkingRequest checks if an email can be linked
message CheckEmailLinkingRequest {
  // Email address to check
  string email = 1;
}

// CheckEmailLinkingResponse returns email linking validation result
message CheckEmailLinkingResponse {
  // Whether the email can be linked
  bool can_link = 1;

  // Error message if cannot link
  optional string error = 2;

  // Existing user info if email is already linked
  optional ExistingUserInfo existing_user = 3;
}

// LinkEmailToUserRequest links an email/password to the authenticated user
message LinkEmailToUserRequest {
  // Email address to link
  string email = 1;

  // Password for the email account
  string password = 2;
}

// LinkEmailToUserResponse returns the result of email linking
message LinkEmailToUserResponse {
  // Success indicator
  bool success = 1;

  // Success message
  string message = 2;

  // Updated user data
  User user = 3;
}

// GetUserAuthStateRequest gets the authentication state
message GetUserAuthStateRequest {
  // User ID (optional - defaults to authenticated user)
  optional string user_id = 1;
}

// GetUserAuthStateResponse returns the user's authentication state
message GetUserAuthStateResponse {
  // Authentication type
  string auth_type = 1; // "email", "wallet", or "linked"

  // Primary authentication type
  string primary_auth_type = 2; // "email" or "wallet"

  // Email address (if linked)
  optional string email = 3;

  // Wallet address (if linked)
  optional string wallet_address = 4;

  // Whether email is linked
  bool is_email_linked = 5;

  // Whether wallet is linked
  bool is_wallet_linked = 6;
}

// ExistingUserInfo contains information about an existing user
message ExistingUserInfo {
  // User ID
  string id = 1;

  // Email address (if available)
  optional string email = 2;

  // Wallet address (if available)
  optional string wallet_address = 3;

  // Authentication type
  string auth_type = 4;
}


