using Edu.Model.Entity.Course;
using Edu.Model.Entity.EduTask;
using Edu.Model.ViewModel.EduTask;
using Edu.Repository.Course;
using Edu.Repository.EduTask;
using System.Collections.Generic;
using VT.FW.AOP.CustomerAttribute;
using VT.FW.DB;

namespace Edu.Module.EduTask
{
    /// <summary>
    /// 临时上课邀请处理类
    /// </summary>
    public class TempInvitationClassModule
    {
        /// <summary>
        /// 教务单据仓储层对象
        /// </summary>
        private readonly RB_Education_ReceiptRepository education_ReceiptRepository = new RB_Education_ReceiptRepository();

        /// <summary>
        /// 临时上课邀请计划仓储层对象
        /// </summary>
        private readonly RB_Student_TempInvitationRepository student_TempInvitationRepository = new RB_Student_TempInvitationRepository();

         /// <summary>
        /// 获取临时上课邀请列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_TempInvitation_ViewModel> GetTemporaryInvitationListRepository(RB_Student_TempInvitation_ViewModel query)
        {
            return student_TempInvitationRepository.GetStundetTempInvitationListRepository(query);
        }

        /// <summary>
        /// 新增修改停课申请
        /// </summary>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool SetStudentTempInvitationModule(RB_Student_TempInvitation_ViewModel extModel, string receiptFile)
        {
            bool flag = false;
            if (extModel.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Student_TempInvitation_ViewModel.OrderGuestIds),extModel.OrderGuestIds },
                    {nameof(RB_Student_TempInvitation_ViewModel.ClassId),extModel.ClassId },
                    {nameof(RB_Student_TempInvitation_ViewModel.CourseId),extModel.CourseId },
                    {nameof(RB_Student_TempInvitation_ViewModel.ClassTimeIds),extModel.ClassTimeIds },
                    {nameof(RB_Student_TempInvitation_ViewModel.TeacherId),extModel.TeacherId },
                    {nameof(RB_Student_TempInvitation_ViewModel.School_Id),extModel.School_Id},
                    {nameof(RB_Student_TempInvitation_ViewModel.UpdateBy),extModel.UpdateBy },
                    {nameof(RB_Student_TempInvitation_ViewModel.UpdateTime),extModel.UpdateTime },
                };
                flag = student_TempInvitationRepository.Update(fileds, new WhereHelper(nameof(RB_Temporary_Invitation_ViewModel.Id), extModel.Id));
            }
            else
            {
                var newId = student_TempInvitationRepository.Insert(extModel);
                extModel.Id = newId;
                flag = newId > 0;
                if (flag)
                {
                    var educationReceipt = new RB_Education_Receipt()
                    {
                        Id = 0,
                        Title = "临时上课邀请申请",
                        ReceiptType = Common.Enum.Finance.ReceiptTypeEnum.InvitationClass,
                        RelationId = newId,
                        ClassId = extModel.ClassId,
                        Group_Id = extModel.Group_Id,
                        School_Id = extModel.School_Id,
                        CreateBy = extModel.CreateBy,
                        CreateTime = extModel.CreateTime,
                        UpdateBy = extModel.UpdateBy,
                        UpdateTime = extModel.UpdateTime,
                        VerifyStatus = Common.Enum.EduTask.EduTaskRrocessStatus.NotAudit,
                        ReceiptFile = receiptFile
                    };
                    flag = education_ReceiptRepository.SetEducationReceiptRepository(educationReceipt, out string message);
                }
            }
            return flag;
        }
    }
}
