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

namespace TeleWave.Application.Library.SetShowOriginalName;

public sealed class SetShowOriginalNameCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<SetShowOriginalNameCommand, Result>
{
    public async Task<Result> Handle(
        SetShowOriginalNameCommand command,
        CancellationToken cancellationToken
    )
    {
        var show = await dbContext.Shows.FirstOrDefaultAsync(
            s => s.Id == command.Id,
            cancellationToken
        );
        if (show is null)
            return Result.Failure(ShowErrors.NotFound);

        show.SetOriginalName(command.OriginalName);
        return Result.Success();
    }
}
