using System.Threading.Channels;
using UniVerse.Application.Interfaces;

namespace UniVerse.Api.BackgroundServices;

public sealed class ReviewAnalysisQueue : IReviewAnalysisQueue
{
    private readonly Channel<int> _channel = Channel.CreateUnbounded<int>(new UnboundedChannelOptions
    {
        SingleReader = false,
        SingleWriter = false
    });

    public async Task EnqueueAsync(int reviewId, CancellationToken cancellationToken = default)
    {
        await _channel.Writer.WriteAsync(reviewId, cancellationToken);
    }

    public IAsyncEnumerable<int> ReadAllAsync(CancellationToken cancellationToken) =>
        _channel.Reader.ReadAllAsync(cancellationToken);
}
