using Edu.Common.API;
using Edu.Common.Enum.Course;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.EduTask;
using Edu.Module.Course;
using Edu.Module.EduTask;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Edu.WebApi.Controllers.EduTask
{
    /// <summary>
    /// 改变流程相关申请
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class TempInvitationClassController : BaseController
    {
        /// <summary>
        /// 临时上课邀请处理类对象
        /// </summary>
        private readonly TempInvitationClassModule tempInvitationClassModule = AOP.AOPHelper.CreateAOPObject<TempInvitationClassModule>();

        /// <summary>
        /// 班级处理类对象
        /// </summary>
        private readonly ClassModule classModule = AOP.AOPHelper.CreateAOPObject<ClassModule>();
        /// <summary>
        /// 新增修改班级调课
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentStopClass()
        {
            var model = new RB_Student_TempInvitation_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                ClassId = base.ParmJObj.GetInt("ClassId"),
                ClassTimeId = base.ParmJObj.GetInt("ClassTimeId"),
                ClassPlanId = base.ParmJObj.GetInt("ClassPlanId"),
                OrderGuestIds = base.ParmJObj.GetStringValue("OrderGuestIds"),
                Remarks = base.ParmJObj.GetStringValue("Remarks")
            };
            if (string.IsNullOrWhiteSpace(model.OrderGuestIds))
            {
                return ApiResult.Failed("请选择您要邀请的学生");
            }

            if (model.ClassId == 0)
            {
                return ApiResult.Failed("请选择您要邀请上课的班级");
            }

            if (model.ClassPlanId == 0 || model.ClassTimeId == 0)
            {
                return ApiResult.Failed("请选择您要邀请的时间");
            }
            var classModel = classModule.GetClassModule(model.ClassId);
            model.CourseId = classModel.CouseId;
            model.TeacherId = classModel.Teacher_Id;
            model.School_Id = classModel.School_Id;
            if (model.Id == 0)
            {
                model.CreateBy = base.UserInfo.Id;
                model.CreateTime = DateTime.Now;
                model.Group_Id = base.UserInfo.Group_Id;
            }
            model.UpdateBy = base.UserInfo.Id;
            model.UpdateTime = DateTime.Now;
            bool flag = tempInvitationClassModule.SetStudentTempInvitationModule(model);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }




        //public ApiResult TestUpdateClassPlan()
        //{

        //    int id = base.ParmJObj.GetInt("Id");
        //    var result = changeClassPlanModule.UpdateChangeClassPlan(id);
        //    return ApiResult.Success("");
        //}
    }
}
