using Mall.Model.Entity.Education;
using Mall.Model.Entity.User;
using Mall.Model.Extend.Education;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mall.Repository.Education
{
    public class RB_Education_CouponSelfMotionMemberRepository : BaseRepository<RB_Education_CouponSelfMotionMember>
    {
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Education_CouponSelfMotionMember); } }

        // <summary>
        /// 表名称
        /// </summary>
        public string UserTableName { get { return nameof(RB_Member_User); } }

        /// <summary>
        /// 获取发放优惠券的人员信息
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Education_CSelfMotionMember_Extend> GetListRepository(RB_Education_CSelfMotionMember_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@$" SELECT a.*,b.`Name`,b.Photo  FROM {TableName} as a 
LEFT JOIN {UserTableName} as b on a.UserId = b.ID WHERE   a.{nameof(RB_Education_CSelfMotionMember_Extend.Status)}=0");
            if (query != null)
            {
                if (query.TenantId > 0)
                {
                    builder.Append($" AND a.{nameof(RB_Education_CSelfMotionMember_Extend.TenantId)}={query.TenantId}");
                }

                if (query.MallBaseId > 0)
                {
                    builder.Append($" AND a.{nameof(RB_Education_CSelfMotionMember_Extend.MallBaseId)}={query.MallBaseId}");
                }
                if (query.SelfMotionId > 0)
                {
                    builder.Append($" AND a.{nameof(RB_Education_CSelfMotionMember_Extend.SelfMotionId)}={query.SelfMotionId}");
                }
                if (query.UserId > 0)
                {
                    builder.Append($" AND a.{nameof(RB_Education_CSelfMotionMember_Extend.UserId)}={query.UserId}");
                }

                //if (!string.IsNullOrWhiteSpace(query.PriceIds))
                //{
                //    builder.Append($" AND a.{nameof(RB_Education_CSelfMotionMember_Extend.RulesPriceId)} in ({query.PriceIds})");
                //}
            }
            return Get<RB_Education_CSelfMotionMember_Extend>(builder.ToString()).ToList();
        }
    }
}
