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

namespace TeleWave.Application.Images.UploadImage;

public sealed class UploadImageCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<UploadImageCommand, Result<Guid>>
{
    public Task<Result<Guid>> Handle(
        UploadImageCommand command,
        CancellationToken cancellationToken
    )
    {
        var image = Image.Create(command.Category, command.Extension, command.OriginalFileName);
        dbContext.Images.Add(image);
        return Task.FromResult(Result.Success(image.Id));
    }
}
