using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

namespace Knot.Modules.TelegramImport.Infrastructure.Background;

public enum ImportJobStatus
{
    Queued,
    Processing,
    Completed,
    Failed
}

public class ImportJobInfo
{
    public Guid JobId { get; set; }
    public ImportJobStatus Status { get; set; }
    public int TotalMessages { get; set; }
    public int ProcessedMessages { get; set; }
    public string? ErrorMessage { get; set; }
}

public interface IImportJobStore
{
    void AddOrUpdate(ImportJobInfo info);
    bool TryGet(Guid jobId, out ImportJobInfo? info);
}

public sealed class ImportJobStore : IImportJobStore
{
    private readonly ConcurrentDictionary<Guid, ImportJobInfo> _jobs = new();

    public void AddOrUpdate(ImportJobInfo info) => _jobs[info.JobId] = info;
    public bool TryGet(Guid jobId, out ImportJobInfo? info) => _jobs.TryGetValue(jobId, out info);
}
