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

namespace Application.Features.Admin.Channel.List.Delete;

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

        var list = await db.Channel.Where(c => request.IDs.Contains(c.ID)).ToListAsync(ct);

        if (list.Count < 1)
        {
            return;
        }

        db.Channel.RemoveRange(list);

        await db.SaveChangesAsync(ct);
    }
}