using Hotline.CallCenter.Tels;
using Hotline.Repository.SqlSugar.DataPermissions;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.CallCenter;

public class TelGroupRepository : BaseRepository<TelGroup>, ITelGroupRepository, IScopeDependency
{
    public TelGroupRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
    {
    }

    public async Task UpdateNavTelsAsync(TelGroup group, CancellationToken cancellationToken = default)
    {
        await Db.UpdateNav(group)
            .Include(d => d.Tels, new UpdateNavOptions { ManyToManyIsUpdateA = true })
            .ExecuteCommandAsync();
    }

    public async Task AddNavTelsAsync(TelGroup group, CancellationToken cancellationToken = default)
    {
        await Db.InsertNav(group).Include(d => d.Tels).ExecuteCommandAsync();
    }
}