using Application.Abstractions.Data;
using Application.Abstractions.Messaging;
using Microsoft.EntityFrameworkCore;

namespace Application.Features.Admin.Forum.Trash.Comment.PermanentDelete;

public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
{
    public async Task Handle(Command request, CancellationToken ct)
    {
        if (request.IDs is null || request.IDs.Length == 0)
        {
            return;
        }

        var comments = await db.Comment.Where(c => request.IDs.Contains(c.ID) && c.IsDeleted).ToListAsync(ct);

        // 소프트 삭제 시 이미 카운트가 감소되었으므로 영구 삭제에서는 카운트를 건드리지 않음
        db.Comment.RemoveRange(comments);

        await db.SaveChangesAsync(ct);
    }
}