using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Stories.Abstractions;
using Knot.Modules.Stories.Domain;
using MongoDB.Driver;

namespace Knot.Modules.Stories.Infrastructure.Persistence.Mongo;

public sealed class StoryQueryService : IStoryQueryService
{
    private readonly IMongoCollection<Story> _stories;

    public StoryQueryService(IMongoDatabase database)
    {
        _stories = database.GetCollection<Story>("stories");
    }

    public async Task<List<StoryInfo>> GetAllStoriesAsync(CancellationToken cancellationToken)
    {
        var stories = await _stories.Find(_ => true).ToListAsync(cancellationToken);
        return stories.Select(s => new StoryInfo(s.Id, s.MediaUrl)).ToList();
    }
}
