namespace MossyUpdater.Services
{
    public interface IDownloadService
    {
        Task<DownloadResult> DownloadFileAsync(string url, string destinationPath, IProgress<DownloadProgress>? progress = null, CancellationToken cancellationToken = default);
        Task<FileUpdateInfo> CheckForUpdatesAsync(string url, string localFilePath, CancellationToken cancellationToken = default);
        void UnblockFile(string filePath);
    }

    public class DownloadResult
    {
        public bool Success { get; set; }
        public string? ErrorMessage { get; set; }
        public long BytesDownloaded { get; set; }
        public TimeSpan Duration { get; set; }
    }

    public class DownloadProgress
    {
        public long BytesReceived { get; set; }
        public long? TotalBytes { get; set; }
        public double ProgressPercentage => TotalBytes.HasValue && TotalBytes > 0 
            ? (double)BytesReceived / TotalBytes.Value * 100 
            : 0;
        public string Status { get; set; } = string.Empty;
    }

    public class FileUpdateInfo
    {
        public bool UpdateAvailable { get; set; }
        public DateTime? RemoteLastModified { get; set; }
        public DateTime? LocalLastModified { get; set; }
        public long? RemoteSize { get; set; }
        public long? LocalSize { get; set; }
        public string? ErrorMessage { get; set; }
    }
}