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

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

public class SetAnnouncementDateCommand : IRequest<Unit>
{
    public Guid TitleId { get; init; }
    public DateTimeOffset? Value { get; init; }

}

public class SetAnnouncementDateCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<SetAnnouncementDateCommand, Unit>
{
    public async Task<Unit> Handle(SetAnnouncementDateCommand request, CancellationToken cancellationToken)
    {
        var title = await titleGateway.GetById(request.TitleId, cancellationToken);
        title.CommonProperties.SetAnnouncementDate(request.Value);
        await titleGateway.Update(title, cancellationToken);
        return Unit.Value;
    }
}