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
{
    public class RB_Msg_BaseRepository : BaseRepository<RB_Msg_Base>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Msg_Base); } }

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


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