Files
test/Assets/Tech3C/Runtime/Tech3CCallbacks.cs
2026-02-02 19:21:45 +07:00

151 lines
5.0 KiB
C#

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