using System;
using System.Collections.Generic;
using System.Text;
using Edu.Model.Entity.System;
using Edu.Repository.System;
using VT.FW.DB;

namespace Edu.Module.System
{
    public class HolidayModule
    {
        /// <summary>
        /// 订单学员仓储层对象
        /// </summary>
        private readonly RB_System_HolidayRepository holidayRepository = new RB_System_HolidayRepository();



        /// <summary>
        /// 节假日列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="model">查询条件</param>
        /// <param name="count">总条数</param>
        /// <returns></returns>
        public List<RB_System_Holiday> GetPageList(int pageIndex, int pageSize, RB_System_Holiday model, out long count)
        {
            return holidayRepository.GetPageList(pageIndex, pageSize, model, out count);
        }



        /// <summary>
        /// 判断某一天是否在节假日里
        /// </summary>
        /// <param name="NowDay"></param>
        /// <returns></returns>
        public List<RB_System_Holiday> GetDayhList(string NowDay)
        {
            return holidayRepository.GetDayhList(NowDay);
        }


        /// <summary>
        /// 判断某一个时间段是否在节假日里
        /// </summary>
        /// <param name="NowDay"></param>
        /// <returns></returns>
        public List<RB_System_Holiday> GetExistHoliday(string startTime, string endTime)
        {
            return holidayRepository.GetExistHoliday(startTime, endTime);
        }

        /// <summary>
        /// 获取节假日详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RB_System_Holiday GetEntity(object id)
        {

            return holidayRepository.GetEntity(id);
        }

        /// <summary>
        /// 新增/修改节假日
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetHoliday(RB_System_Holiday model)
        {
            if (model.HolidayId == 0)
            {
                return holidayRepository.Insert(model) > 0;
            }
            else
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_System_Holiday.StartTime),model.StartTime},
                    {nameof(RB_System_Holiday.EndTime),model.EndTime },
                    {nameof(RB_System_Holiday.DayType),model.DayType }
                };
                return holidayRepository.Update(fileds, new WhereHelper(nameof(model.HolidayId), model.HolidayId));
            }
        }

        /// <summary>
        /// 删除节假日
        /// </summary>
        /// <param name="HolidayId"></param>
        /// <returns></returns>
        public bool DelHoliday(int HolidayId)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_System_Holiday.Status),1}
                };
            return holidayRepository.Update(fileds, new WhereHelper(nameof(HolidayId), HolidayId));
        }



        /// <summary>
        ///批量新增节假日
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetHoliday(List<RB_System_Holiday> list)
        {
            return holidayRepository.InsertBatch(list);
        }


    }
}
