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

namespace Application.Features.Api.DonationGoal.DeleteConfig;

internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
{
    public async Task Handle(Command request, CancellationToken ct)
    {
        var config = await db.DonationGoalConfig
            .FirstOrDefaultAsync(c => c.ID == request.ID && c.ChannelID == request.ChannelID, ct);

        if (config is null)
        {
            return;
        }

        db.DonationGoalConfig.Remove(config);
        await db.SaveChangesAsync(ct);
    }
}