using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.ViewModels.Query;
using New_College.Model.ViewModels.Result;

namespace New_College.Api.Controllers.Front
{

    /// <summary>
    ///招生计划
    /// </summary>
    [Route("api/front/[controller]/[action]")]
    [ApiController]
    public class EnrollMentPlansController : ControllerBase
    {
        private readonly IT_EnrollmentPlaneServices t_EnrollmentPlane;
        public EnrollMentPlansController(IT_EnrollmentPlaneServices enrollmentPlaneServices)
        {
            this.t_EnrollmentPlane = enrollmentPlaneServices;
        }


        /// <summary>
        /// 根据院校和专业获取招生计划列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<List<EnrollmentPlansResult>>> GetEnrollmentPlans([FromQuery] EnrollmentPlanRequest request)
        {
            try
            {
                var planinfo = await this.t_EnrollmentPlane.Query(e => e.IsDelete == false && e.Area_Id == request.AreaId && e.Years == request.Years);
                if (planinfo.Any())
                {
                    request.PlanId = planinfo.FirstOrDefault().Id;
                    var result = await this.t_EnrollmentPlane.GetEnrollmentPlans(request);
                    return new MessageModel<List<EnrollmentPlansResult>>()
                    {
                        msg = "success",
                        response = result,
                        success = true
                    };
                }
                else
                {
                    return new MessageModel<List<EnrollmentPlansResult>>()
                    {
                        msg = "相关信息更新中...",
                    };
                }
            }
            catch (Exception ex)
            {
                return new MessageModel<List<EnrollmentPlansResult>>()
                {
                    msg = ex.Message
                };
            }
        }




    }
}
