using LiteCqrs;
using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Common.Models;

namespace TeleWave.Application.Broadcast.Bumpers;

public sealed class ClearBumperTemplateBackgroundCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<ClearBumperTemplateBackgroundCommand, Result>
{
    public async Task<Result> Handle(
        ClearBumperTemplateBackgroundCommand command,
        CancellationToken cancellationToken
    )
    {
        var template = await BumperTemplateLoader.LoadAsync(
            dbContext,
            command.TemplateId,
            cancellationToken
        );
        if (template is null)
            return Result.Failure(BumperErrors.TemplateNotFound);

        template.ClearBackgroundImage();
        return Result.Success();
    }
}
