using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LinqKit;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using New_College.Model.Request;

namespace New_College.Api.Controllers.Front
{

    /// <summary>
    /// 新高考选科
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize]
    public class FrontSelectionController : ControllerBase
    {
        private readonly ISubjectSelectionServices _selectionServices;
        public FrontSelectionController(ISubjectSelectionServices subjectSelection)
        {
            this._selectionServices = subjectSelection;
        }



        /// <summary>
        /// 根据院校和专业名称查询选科组合情况
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<PageModel<SubjectSelection>>> GetSubjectSelects([FromQuery] SelectionServiceRequest request)
        {
            try
            {
                var query = new List<string>();


                var subjectlist = new PageModel<SubjectSelection>();
                if (request.UniversityName != null)
                {
                    query = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(request.UniversityName);
                    subjectlist = await _selectionServices.QueryPage(w => query.Contains(w.UniversityName), request.PageIndex, request.PageSize);
                }
                if (request.MajorName != null)
                {
                    query = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(request.MajorName);
                    subjectlist = await _selectionServices.QueryPage(w => query.Contains(w.MajorName), request.PageIndex, request.PageSize);
                }
                return new MessageModel<PageModel<SubjectSelection>>()
                {
                    msg = "success",
                    response = subjectlist,
                    success = true
                };
            }
            catch (Exception ex)
            {
                return new MessageModel<PageModel<SubjectSelection>>()
                {
                    msg = ex.Message
                };
            }
        }




    }
}
