using System;
namespace Tech3C
{
///
/// Callback for authentication operations (login, register, etc.)
///
public interface IAuthCallback
{
///
/// Called when authentication is successful
///
/// The authenticated user ID
/// The user password
/// The access token
/// The refresh token
/// The type of login used
/// Token expiry timestamp
void OnAuthSuccess(string userId, string password, string accessToken, string refreshToken, LoginType loginType, long expiryTime);
///
/// Called when authentication is cancelled by the user
///
void OnAuthCancelled();
///
/// Called when an error occurs during authentication
///
/// The error code
/// The error message
void OnAuthError(int errorCode, string errorMessage);
}
///
/// Callback for logout operations
///
public interface ILogoutCallback
{
///
/// Called when logout is successful
///
void OnLogoutSuccess();
///
/// Called when an error occurs during logout
///
/// The error code
/// The error message
void OnLogoutError(int errorCode, string errorMessage);
}
///
/// Callback for user info operations
///
public interface IUserInfoCallback
{
///
/// Called when user info is successfully retrieved
///
/// The user ID
/// The username
/// The email address
/// The phone number
void OnUserInfoReceived(string userId, string username, string email, string phone);
///
/// Called when user info retrieval is cancelled
///
void OnUserInfoCancelled();
///
/// Called when an error occurs while retrieving user info
///
/// The error code
/// The error message
void OnUserInfoError(int errorCode, string errorMessage);
}
///
/// Default implementation of IAuthCallback using Unity events
///
[Serializable]
public class AuthCallback : IAuthCallback
{
public event Action OnAuthSuccessEvent;
public event Action OnAuthCancelledEvent;
public event Action OnAuthErrorEvent;
public void OnAuthSuccess(string userId, string password, string accessToken, string refreshToken, LoginType loginType, long expiryTime)
{
OnAuthSuccessEvent?.Invoke(userId, password, accessToken, refreshToken, loginType, expiryTime);
}
public void OnAuthCancelled()
{
OnAuthCancelledEvent?.Invoke();
}
public void OnAuthError(int errorCode, string errorMessage)
{
OnAuthErrorEvent?.Invoke(errorCode, errorMessage);
}
}
///
/// Default implementation of ILogoutCallback using Unity events
///
[Serializable]
public class LogoutCallback : ILogoutCallback
{
public event Action OnLogoutSuccessEvent;
public event Action OnLogoutErrorEvent;
public void OnLogoutSuccess()
{
OnLogoutSuccessEvent?.Invoke();
}
public void OnLogoutError(int errorCode, string errorMessage)
{
OnLogoutErrorEvent?.Invoke(errorCode, errorMessage);
}
}
///
/// Default implementation of IUserInfoCallback using Unity events
///
[Serializable]
public class UserInfoCallback : IUserInfoCallback
{
public event Action OnUserInfoReceivedEvent;
public event Action OnUserInfoCancelledEvent;
public event Action OnUserInfoErrorEvent;
public void OnUserInfoReceived(string userId, string username, string email, string phone)
{
OnUserInfoReceivedEvent?.Invoke(userId, username, email, phone);
}
public void OnUserInfoCancelled()
{
OnUserInfoCancelledEvent?.Invoke();
}
public void OnUserInfoError(int errorCode, string errorMessage)
{
OnUserInfoErrorEvent?.Invoke(errorCode, errorMessage);
}
}
}