using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.System;
using Edu.Model.ViewModel.System;

namespace Edu.Repository.System
{
    /// <summary>
    /// 短信模板仓储层
    /// </summary>
    public class RB_Msg_BaseTemplateRepository : BaseRepository<RB_Msg_BaseTemplate>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Msg_BaseTemplate); } }

        /// <summary>
        /// 获取短信模板配置信息
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Msg_BaseTemplate_ViewModel> GetListRepository(RB_Msg_BaseTemplate_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append($" SELECT * FROM {TableName} where 1=1 ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.Group_Id)}={query.Group_Id}");
                }
                if (query.StoreType > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.StoreType)}={(int)query.StoreType}");
                }
                if (query.BaseTemplateType > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.BaseTemplateType)}={(int)query.BaseTemplateType}");
                }
             
            }
            return Get<RB_Msg_BaseTemplate_ViewModel>(builder.ToString()).ToList();
        }


        /// <summary>
        /// 获取短信模板配置信息
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Msg_BaseTemplate_ViewModel> GetPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Msg_BaseTemplate_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append($" SELECT * FROM {TableName} where 1=1 ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.Group_Id)}={query.Group_Id}");
                }
                if (query.StoreType > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.StoreType)}={(int)query.StoreType}");
                }
                if (query.BaseTemplateType > 0)
                {
                    builder.Append($" AND {nameof(RB_Msg_BaseTemplate.BaseTemplateType)}={(int)query.BaseTemplateType}");
                }
            }
            return GetPage<RB_Msg_BaseTemplate_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}
