using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Conversations.Abstractions;
using Microsoft.EntityFrameworkCore;

namespace Knot.Modules.Conversations.Infrastructure.Persistence;

public sealed class ChatQueryService : IChatQueryService
{
    private readonly ChatsDbContext _context;

    public ChatQueryService(ChatsDbContext context)
    {
        _context = context;
    }

    public async Task<List<ChatInfo>> GetAllChatsAsync(CancellationToken cancellationToken)
    {
        var chats = await _context.Chats.AsNoTracking().ToListAsync(cancellationToken);
        return chats.Select(c => new ChatInfo(c.Id, c.Avatar)).ToList();
    }
}
