using Amazon.Runtime.Internal;
using Exam.Share;
using Exam.Share.ViewResponses.Practices;
using Hotline.Application.Exam.Constants.ApiRoutes;
using Hotline.Application.Exam.Interface.Practices;
using Hotline.Share.Dtos.Practices;
using Hotline.Share.Requests.Exam;
using Hotline.Share.Requests.TestPaper;
using Hotline.Share.ViewResponses.Exam;
using Hotline.Share.ViewResponses.Practices;
using Microsoft.AspNetCore.Mvc;

namespace Hotline.Api.Controllers.Exam
{
    public class PracticeController : BaseController
    {
        private readonly IPracticeService _practiceService;

        public PracticeController(IPracticeService practiceService)
        {
            this._practiceService = practiceService;
        }

        /// <summary>
        /// 获取自我练习试题类型和Id
        /// </summary>
        /// <param name="examQuestionRequest"></param>
        /// <returns></returns>
        [HttpGet(PracticeApiRoute.GetPracticeQuestionViewResponses)]
        public async Task<List<PracticeQuestionViewResponse>> GetPracticeQuestionViewResponses([FromQuery] PracticeQuestionGroupRequest practiceQuestionGroupRequest)
        {

            return await _practiceService.GetPracticeQuestionViewResponses(practiceQuestionGroupRequest);
        }

        /// <summary>
        /// 获取练习试题
        /// </summary>
        /// <param name="practiceQuestionRequest"></param>
        /// <returns></returns>
        [HttpGet(PracticeApiRoute.GetPracticeQuestionDto)]
        public async Task<PracticeQuestionDto> GetPracticeQuestion([FromQuery] PracticeQuestionRequest practiceQuestionRequest)
        {
            return await _practiceService.GetPracticeQuestion(practiceQuestionRequest);
        }

        /// <summary>
        /// 练习
        /// </summary>
        /// <param name="submitPracticeDto"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost(PracticeApiRoute.Practice)]
        public async Task<PracticeQuestionDto> Practice([FromBody]SubmitPracticeDto submitPracticeDto)
        {
            return await _practiceService.Practice(submitPracticeDto,HttpContext.RequestAborted);
        }

        /// <summary>
        /// 获取练习记录
        /// </summary>
        /// <param name="practicePagedRequest"></param>
        /// <returns></returns>
        [HttpPost(PracticeApiRoute.GetPagedList)]
        public async Task<PracticePageViewResponse> GetPagedList([FromBody]PracticePagedRequest practicePagedRequest)
        {
            var practicePageViewResponse = await _practiceService.GetPagedListAsync(practicePagedRequest);
            return practicePageViewResponse as PracticePageViewResponse;
        }

        /// <summary>
        /// 完成练习记录
        /// </summary>
        /// <returns></returns>
        [HttpPost(PracticeApiRoute.Complete)]
        public async Task Complete([FromBody]CompletePracticeRecordDto completePracticeRecordDto)
        {
            await _practiceService.Complete(completePracticeRecordDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 获取查看练习习题
        /// </summary>
        /// <param name="practiceQuestionGroupRequest"></param>
        /// <returns></returns>
        [HttpGet(PracticeApiRoute.GetViewPracticeQuestions)]
        public async Task<List<PracticeQuestionViewResponse>> GetViewPracticeQuestions([FromQuery] PracticeQuestionGroupRequest practiceQuestionGroupRequest)
        {
            return await _practiceService.GetViewPracticeQuestions(practiceQuestionGroupRequest);
        }

        /// <summary>
        /// 获取查看练习习题
        /// </summary>
        /// <param name="practiceQuestionGroupRequest"></param>
        /// <returns></returns>
        [HttpGet(PracticeApiRoute.View)]
        public async Task<ViewPracticeQuestionDto> View([FromQuery] PracticeQuestionRequest practiceQuestionRequest)
        {
            return await _practiceService.ViewPracticeQuestion(practiceQuestionRequest);
        }

        /// <summary>
        /// 新增练习
        /// </summary>
        /// <param name="addPracticeDto"></param>
        /// <returns></returns>
        [HttpPost(PracticeApiRoute.Add)]
        public async Task<string> Add([FromBody] AddPracticeDto addPracticeDto)
        {
           return  await _practiceService.AddAsync(addPracticeDto,HttpContext.RequestAborted);
        }

        /// <summary>
        /// 获取标签试题数
        /// </summary>
        /// <param name="tagQuestionCountForPracticeRequest"></param>
        /// <returns></returns>
        [HttpPost(PracticeApiRoute.GetTagQuestionCount)]
        public async Task<TagQuestionCountViewResponse> GetTagQuestionCount([FromBody] TagQuestionCountForPracticeRequest tagQuestionCountForPracticeRequest)
        {
            return await _practiceService.GetTagQuestionCount(tagQuestionCountForPracticeRequest);
        }
    }
}
