using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Share.Dtos.FlowEngine.Workflow;
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 VolunteerRepository : BaseRepository<Volunteer>, IVolunteerRepository, IScopeDependency
{
    public VolunteerRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
    {
    }

    public async Task<Volunteer> GetByPhoneAsync(string? phone)
    {
        if (phone.IsNullOrEmpty()) return null;
        return await Queryable().Where(m => m.PhoneNumber == phone.Trim()).FirstAsync();
    }

    /// <summary>
    /// 是否是志愿者
    /// </summary>
    /// <param name="phoneNumber"></param>
    /// <returns></returns>
    public async Task<bool> IsVolunteerAsync(string? phoneNumber)
    {
        if (phoneNumber.IsNullOrEmpty()) return false;
        return await Queryable().Where(m => m.PhoneNumber == phoneNumber.Trim()).AnyAsync();
    }
}
