namespace MCPForUnity.Editor.Services
{
///
/// Service for checking package updates and version information
///
public interface IPackageUpdateService
{
///
/// Checks if a newer version of the package is available
///
/// The current package version
/// Update check result containing availability and latest version info
UpdateCheckResult CheckForUpdate(string currentVersion);
///
/// Returns a cached update result if one exists for today, or null if a network fetch is needed.
/// Main-thread only (reads EditorPrefs).
///
UpdateCheckResult TryGetCachedResult(string currentVersion);
///
/// Performs only the network fetch and version comparison (no EditorPrefs access).
/// Safe to call from a background thread.
///
UpdateCheckResult FetchAndCompare(string currentVersion);
///
/// Performs only the network fetch and version comparison using pre-computed installation info.
/// Use this overload when calling from a background thread to avoid main-thread-only API calls.
///
UpdateCheckResult FetchAndCompare(string currentVersion, bool isGitInstallation, string gitBranch);
///
/// Caches a successful fetch result in EditorPrefs. Must be called from the main thread.
///
void CacheFetchResult(string currentVersion, string fetchedVersion);
///
/// Compares two version strings to determine if the first is newer than the second
///
/// First version string
/// Second version string
/// True if version1 is newer than version2
bool IsNewerVersion(string version1, string version2);
///
/// Determines if the package was installed via Git or Asset Store
///
/// True if installed via Git, false if Asset Store or unknown
bool IsGitInstallation();
///
/// Determines the Git branch to check for updates (e.g. "main" or "beta").
/// Must be called from the main thread (uses Unity PackageManager APIs).
///
string GetGitUpdateBranch(string currentVersion);
///
/// Clears the cached update check data, forcing a fresh check on next request
///
void ClearCache();
}
///
/// Result of an update check operation
///
public class UpdateCheckResult
{
///
/// Whether an update is available
///
public bool UpdateAvailable { get; set; }
///
/// The latest version available (null if check failed or no update)
///
public string LatestVersion { get; set; }
///
/// Whether the check was successful (false if network error, etc.)
///
public bool CheckSucceeded { get; set; }
///
/// Optional message about the check result
///
public string Message { get; set; }
}
}