using Edu.Common.API;
using Edu.Common.Plugin;
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;

namespace Edu.WebApi.Controllers.EduTask
{
    /// <summary>
    /// 订单转班、分拆控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class OrderChangeController : BaseController
    {
        /// <summary>
        /// 订单转班、分拆处理类对象
        /// </summary>
        private readonly OrderChangeModule orderChangeModule = AOP.AOPHelper.CreateAOPObject<OrderChangeModule>();

        /// <summary>
        /// 班级处理类对象
        /// </summary>
        private readonly ClassModule classModule = AOP.AOPHelper.CreateAOPObject<ClassModule>();

        /// <summary>
        /// 新增订单转班申请
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetOrderChange()
        {
            var model = new RB_Order_Change_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                SourceOrderId = base.ParmJObj.GetInt("SourceOrderId"),
                ChangeType = base.ParmJObj.GetInt("ChangeType"),
                NewClassId = base.ParmJObj.GetInt("NewClassId"),
                NewCourseId = base.ParmJObj.GetInt("NewCourseId"),
                EffectiveDate = base.ParmJObj.GetDateTime("EffectiveDate"),
                Remarks = base.ParmJObj.GetStringValue("Remarks"),
                OrderGuestId=base.ParmJObj.GetInt("OrderGuestId"),
            };
            var classModel = classModule.GetClassModule(model.NewClassId );
            model.CreateBy = base.UserInfo.Id;
            model.CreateTime = DateTime.Now;
            model.Group_Id = base.UserInfo.Group_Id;
            model.School_Id = classModel.School_Id;
            model.UpdateBy = base.UserInfo.Id;
            model.UpdateTime = DateTime.Now;
            bool flag = orderChangeModule.SetOrderChangeModule(model, out string message);
            return flag ? ApiResult.Success() : ApiResult.Failed(message: message);
        }
    }
}
