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

namespace TeleWave.Application.Programming.Groups.CreateGroup;

public sealed class CreateGroupCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<CreateGroupCommand, Result<Guid>>
{
    public Task<Result<Guid>> Handle(
        CreateGroupCommand command,
        CancellationToken cancellationToken
    )
    {
        var group = Group.Create(command.Name, command.Description);
        dbContext.Groups.Add(group);
        return Task.FromResult(Result.Success(group.Id));
    }
}
