using Edu.Common.Enum;
using Edu.Model.ViewModel.Course;
using Edu.Repository.Course;
using System;
using System.Collections.Generic;
using System.Text;
using VT.FW.DB;

namespace Edu.Module.Course
{
    /// <summary>
    /// 课程章节单词处理类
    /// </summary>
    public class CourseWordsModule
    {
        /// <summary>
        /// 课程章节单词仓储层对象
        /// </summary>
        private readonly RB_Course_WordsRepository course_WordsRepository = new RB_Course_WordsRepository();

        /// <summary>
        /// 获取课程单词分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Course_Words_Extend> GetCourseWordsPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_Words_Extend query)
        {
            var list = course_WordsRepository.GetCourseWordsPageRepository(pageIndex, pageSize, out rowsCount, query);
            return list;
        }

        /// <summary>
        /// 获取课程单词列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Course_Words_Extend> GetCourseWordsListModule(RB_Course_Words_Extend query)
        {
            var list = course_WordsRepository.GetCourseWordsListRepository(query);
            return list;
        }

        /// <summary>
        /// 批量添加课程单词
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool BatchInsertCourseWordsModule(List<RB_Course_Words_Extend> list)
        {
            return course_WordsRepository.BatchInsertCourseWordsRepository(list);
        }

        /// <summary>
        /// 新增修改课程单词
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetCourseWordsModule(RB_Course_Words_Extend model)
        {
            bool flag = false;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Course_Words_Extend.ChapterId),model.ChapterId },
                    {nameof(RB_Course_Words_Extend.WordType),model.WordType },
                    {nameof(RB_Course_Words_Extend.WordContent),model.WordContent },
                    {nameof(RB_Course_Words_Extend.WordTone),model.WordTone },
                    {nameof(RB_Course_Words_Extend.WordWrite),model.WordWrite },
                    {nameof(RB_Course_Words_Extend.ChineseMean),model.ChineseMean },
                    {nameof(RB_Course_Words_Extend.FileUrl),model.FileUrl },
                    {nameof(RB_Course_Words_Extend.UpdateBy),model.UpdateBy },
                    {nameof(RB_Course_Words_Extend.UpdateTime),model.UpdateTime },
                };
                flag = course_WordsRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Words_Extend.Id), model.Id));
            }
            else
            {
                var newId = course_WordsRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取单词详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Course_Words_Extend GetCourseWordsModule(object Id)
        {
            var extModel = course_WordsRepository.GetEntity<RB_Course_Words_Extend>(Id);
            return extModel;
        }

        /// <summary>
        /// 根据编号删除单词
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool RemoveCourseWordsModule(object Id)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Course_Words_Extend.Status),(int)DateStateEnum.Delete },
            };
            bool flag = course_WordsRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Words_Extend.Id), Id));
            return flag;
        }
    }
}
