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

namespace Mall.Repository.MarketingCenter
{
    public class RB_DepositRepository : BaseRepository<RB_Deposit>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Deposit); } }
        /// <summary>
        /// 卡券信息列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Deposit_Extend> GetDepositPageList(int pageIndex, int pageSize, out long rowCount, RB_Deposit_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append($" SELECT * FROM {TableName} WHERE  {nameof(RB_Deposit_Extend.Status)}=0");
            if (query != null)
            {
                if (query.TenantId > 0)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.TenantId)}={query.TenantId}");
                }
                if (query.PickupCenter > -1)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.PickupCenter)}={query.PickupCenter}");
                }
                if (query.MallBaseId > 0)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.MallBaseId)}={query.MallBaseId}");
                }
                if (!string.IsNullOrWhiteSpace(query.Name))
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.Name)} like '%{query.Name}%'");
                }
            }
            return GetPage<RB_Deposit_Extend>(pageIndex, pageSize, out rowCount, builder.ToString()).ToList();
        }


        /// <summary>
        /// 卡券信息列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Deposit_Extend> GetDepositList(RB_Deposit_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append($" SELECT * FROM {TableName} WHERE {nameof(RB_Deposit_Extend.Status)}=0 ");
            if (query != null)
            {
                if (query.ID > 0)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.ID)}={query.ID}");
                }
                if (query.TenantId > 0)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.TenantId)}={query.TenantId}");
                }
                if (query.PickupCenter > -1)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.PickupCenter)}={query.PickupCenter}");
                }
                if (query.MallBaseId > 0)
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.MallBaseId)}={query.MallBaseId}");
                }
                if (!string.IsNullOrWhiteSpace(query.Name))
                {
                    builder.Append($" AND {nameof(RB_Deposit_Extend.Name)} like '%{query.Name}%'");
                }
            }
            return Get<RB_Deposit_Extend>(builder.ToString()).ToList();
        }
    }
}
