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

namespace TeleWave.Application.Library.Collections.CreateCollection;

public sealed class CreateCollectionCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<CreateCollectionCommand, Result<Guid>>
{
    public Task<Result<Guid>> Handle(
        CreateCollectionCommand command,
        CancellationToken cancellationToken
    )
    {
        var collection = Collection.Create(command.Name, command.Description);
        dbContext.Collections.Add(collection);
        return Task.FromResult(Result.Success(collection.Id));
    }
}
