using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Share.Enums.Snapshot;
using Hotline.Share.Tools;
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 RedPackRecordRepository : BaseRepository<RedPackRecord>, IRedPackRecordRepository, IScopeDependency
{
    public RedPackRecordRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
    {
    }

    public async Task<double> GetReceivedTotalAmountAsync(string? openId, CancellationToken cancellationToken)
    {
        if (openId.IsNullOrEmpty()) return 0d;
        return await Queryable()
            .Where(m => m.WXOpenId == openId && m.PickupStatus == ERedPackPickupStatus.Received)
            .Select(m => SqlFunc.AggregateSum(m.Amount))
            .FirstAsync(cancellationToken);
    }
}

