using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Snapshot;
using Hotline.Snapshot.IRepository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.Snapshot;
public class SnapshotOrderPublishRepository : BaseRepository<SnapshotOrderPublish>, ISnapshotOrderPublishRepository, IScopeDependency
{
    public SnapshotOrderPublishRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
    {
    }

    /// <summary>
    /// 添加公开工单并更新小程序工单公开状态
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    new public async Task<string> AddAsync(SnapshotOrderPublish entity, CancellationToken cancellationToken = default)
    {
        await Uow.Db.Ado.BeginTranAsync();
        await Uow.Db.Updateable<OrderSnapshot>()
            .Where(m => m.Id == entity.OrderId)
            .SetColumns(m => m.IsAppOpened, true)
            .ExecuteCommandAsync(cancellationToken);
        var id = await base.AddAsync(entity, cancellationToken);
        await Uow.Db.Ado.CommitTranAsync();
        return id;
    }
}
