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

namespace Edu.Repository.Course
{
    /// <summary>
    /// 班级类型费用设置仓储层
    /// </summary>
    public class RB_Class_TypeRepository : BaseRepository<RB_Class_Type>
    {
        /// <summary>
        /// 获取班级类型费用分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Type_ViewModel> GetClassTypePageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Class_Type_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Class_Type
WHERE 1=1 
");
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_Type_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_Type_ViewModel.Group_Id), query.Group_Id);
                }
            }
            return GetPage<RB_Class_Type_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取班级类型列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Type_ViewModel> GetClassTypeListRepository(RB_Class_Type_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Class_Type
WHERE 1=1 
");
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_Type_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_Type_ViewModel.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.Q_CTypeIds))
                {
                    builder.AppendFormat(" AND {0} in({1}) ", nameof(RB_Class_Type_ViewModel.CTypeId), query.Q_CTypeIds);
                }
            }
            return Get<RB_Class_Type_ViewModel>(builder.ToString()).ToList();
        }
    }
}