using Exam.Application.Interface.Exam;
using Exam.Infrastructure.Data.Entity;
using Exam.Share.ViewResponses.Exam;
using Hotline.Application.Exam.Constants.ApiRoutes;
using Hotline.Application.Exam.Interface.ExamManages;
using Hotline.Repository.SqlSugar.Exam.Interface;
using Hotline.Share.Dtos.TestPapers;
using Hotline.Share.Requests.Exam;
using Hotline.Share.ViewResponses.Exam;
using Mapster;
using Microsoft.AspNetCore.Mvc;

namespace Hotline.Api.Controllers.Exam
{
    public class ExtractRuleController : BaseController
    {
        private readonly IExtractRuleService _extractRuleService;
        public ExtractRuleController(IExtractRuleService extractRuleService)
        {
            _extractRuleService = extractRuleService;
        }

        /// <summary>
        /// 新增考试标签
        /// </summary>
        /// <param name="extractRuleDto"></param>
        /// <returns></returns>
        [HttpPost(ExtractRuleApiRoute.Add)]
        public async Task Add([FromBody] AddExtractRuleDto extractRuleDto)
        {
            await _extractRuleService.AddAsync(extractRuleDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 修改考试标签
        /// </summary>
        /// <param name="extractRuleDto"></param>
        /// <returns></returns>
        [HttpPut(ExtractRuleApiRoute.Update)]
        public async Task Update([FromBody] UpdateExtractRuleDto extractRuleDto)
        {
            await _extractRuleService.UpdateAsync(extractRuleDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 删除考试标签
        /// </summary>
        /// <param name="entityQueryRequest"></param>
        /// <returns></returns>
        [HttpDelete(ExtractRuleApiRoute.Delete)]

        public async Task Delete(EntityQueryRequest entityQueryRequest)
        {
            await _extractRuleService.DeleteAsync(entityQueryRequest, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 获取课件分页列表
        /// </summary>
        /// <param name="sourcewarePagedRequest"></param>
        /// <returns></returns>
        [HttpPost(ExtractRuleApiRoute.GetPagedList)]
        public async Task<ExtractRulePageViewResponse> GetPagedList([FromBody] ExtractRulePagedRequest extractRulePagedRequest)
        {
            var sourcewarePageViewResponse = await _extractRuleService.GetPagedListAsync(extractRulePagedRequest);

            return sourcewarePageViewResponse as ExtractRulePageViewResponse;
        }


        /// <summary>
        /// 获取课件分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet(ExtractRuleApiRoute.Get)]
        public async Task<ExtractRuleDto> Get(string id)
        {
            var extractRuleDto = await _extractRuleService.GetAsync(new EntityQueryRequest
            {
                Id = id
            });

            return extractRuleDto;
        }

        /// <summary>
        /// 获取抽题规则列表
        /// </summary>
        /// <param name="extractRuleRequest"></param>
        /// <returns></returns>
        [HttpGet(ExtractRuleApiRoute.GetList)]
        public async Task<List<ExtractRuleViewResponse>> GetList([FromQuery] ExtractRuleRequest extractRuleRequest)
        {
            var extractRulePagedRequest = extractRuleRequest.Adapt<ExtractRulePagedRequest>();

            return (await _extractRuleService.GetListAsync(extractRulePagedRequest)).Item2;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tagQuestionRequest"></param>
        /// <returns></returns>
        [HttpPost(ExtractRuleApiRoute.GetTagQuestionCount)]
        public async Task<List<TagQuestionViewResponse>> GetTagQuestionCount([FromBody] TagQuestionRequest tagQuestionRequest)
        {
            var tagQuestionViewResponses = await _extractRuleService.GetTagQuestionCount(tagQuestionRequest);

            return tagQuestionViewResponses;
        }

        /// <summary>
        /// 更新开启状态
        /// </summary>
        /// <param name="statusActionRequests"></param>
        /// <returns></returns>
        [HttpPost(ExtractRuleApiRoute.UpdateStatus)]
        public async Task UpdateStatus([FromBody] List<StatusActionRequest> statusActionRequests)
        {
            await _extractRuleService.UpdateStatus(statusActionRequests, HttpContext.RequestAborted);
        }
    }
}
