using System.Collections.Concurrent;

namespace Pgo.Backend.Services;


public class SimpleDownloadStatusNotificationService
{
    public ConcurrentDictionary<string, DownloadStatus> Status = new();

    //public ConcurrentDictionary<string, DownloadStatus> Status => _status;

    //public string GetStatus(string userName)
    //{
    //    _status.TryGetValue(userName, out var status);
    //    return status;
    //}

    public DownloadStatus UpdateStatus(string userId, bool isDownloading)
    {
        return Status.AddOrUpdate(
            userId,
            new DownloadStatus { UserId = userId, IsDownloading = isDownloading }, 
            (key, existingValue) =>
            {
                existingValue.IsDownloading = isDownloading;
                return existingValue;
            }
        );
    }



    //public bool RemoveStatus(string userName)
    //{
    //    return _status.TryRemove(userName, out _);
    //}

    public class DownloadStatus
    {
        public string? UserId { get; set; }
        public bool IsDownloading { get; set; }
    }
}
