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

namespace Mall.Repository.MarketingCenter
{
    public class RB_Coupon_SelfMotionMemberRepository : RepositoryBase<RB_Coupon_SelfMotionMember>
    {
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Coupon_SelfMotionMember); } }

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

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

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

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