using Indotalent.Infrastructure.Database;
using MediatR;

namespace Indotalent.Features.Serilogs.Database;



public record DeleteSerilogLogsByIdCommand(int Id) : IRequest<bool>;


public class DeleteSerilogLogsByIdHandler :
    IRequestHandler<DeleteSerilogLogsByIdCommand, bool>
{
    private readonly AppDbContext _context;

    public DeleteSerilogLogsByIdHandler(AppDbContext context)
    {
        _context = context;
    }

    public async Task<bool> Handle(DeleteSerilogLogsByIdCommand request, CancellationToken cancellationToken)
    {
        var log = await _context.Set<Data.Entities.SerilogLogs>().FindAsync(request.Id);
        if (log == null) return false;

        _context.Set<Data.Entities.SerilogLogs>().Remove(log);
        return await _context.SaveChangesAsync(cancellationToken) > 0;
    }

}