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

namespace TeleWave.Application.Programming.Templates.Junctions;

public sealed class CreateJunctionCommandHandler(IAppDbContext dbContext)
    : ICommandHandler<CreateJunctionCommand, Result<Guid>>
{
    public Task<Result<Guid>> Handle(
        CreateJunctionCommand command,
        CancellationToken cancellationToken
    )
    {
        var junction = JunctionTemplate.Create(command.Name);
        dbContext.JunctionTemplates.Add(junction);
        return Task.FromResult(Result.Success(junction.Id));
    }
}
