using MediatR;
using Modules.Library.Application.Gateways;

namespace Modules.Library.Application.Commands.Anime.Title.Properties;

public class SetExpirationTimeCommand : IRequest<Unit>
{
    public Guid TitleId { get; set; }
    public TimeSpan ExpirationTime { get; set; }

}

public class SetExpirationTimeCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<SetExpirationTimeCommand, Unit>
{
    public async Task<Unit> Handle(SetExpirationTimeCommand request, CancellationToken cancellationToken)
    {
        var title = await titleGateway.GetById(request.TitleId);
        title.SetExpirationTime(request.ExpirationTime);
        await titleGateway.Update(title);
        return Unit.Value;
    }
}