using Exam.Infrastructure.Data.Entity;
using Exam.Share;
using Exam.Share.ViewResponses.Train;
using Hotline.Application.Exam.Constants.ApiRoutes;
using Hotline.Application.Exam.Interface.Train;
using Hotline.Share.Dtos.Trains;
using Hotline.Share.Requests.Train;
using Microsoft.AspNetCore.Mvc;

namespace Hotline.Api.Controllers.Exam
{
    public class TrainPlanController : BaseController
    {
        private readonly ITrainPlanService _trainTemplateService;

        public TrainPlanController(ITrainPlanService trainTemplateService)
        {
            this._trainTemplateService = trainTemplateService;
        }

        /// <summary>
        /// 新增培训模版
        /// </summary>
        /// <param name="extractRuleDto"></param>
        /// <returns></returns>
        [HttpPost(TrainPlanApiRoute.Add)]
        public async Task Add([FromBody] AddTrainPlanDto extractRuleDto)
        {
            await _trainTemplateService.AddAsync(extractRuleDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 修改培训模版
        /// </summary>
        /// <param name="extractRuleDto"></param>
        /// <returns></returns>
        [HttpPut(TrainPlanApiRoute.Update)]
        public async Task Update([FromBody] UpdateTrainPlanDto extractRuleDto)
        {
            await _trainTemplateService.UpdateAsync(extractRuleDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 删除培训模版
        /// </summary>
        /// <param name="entityQueryRequest"></param>
        /// <returns></returns>
        [HttpDelete(TrainPlanApiRoute.Delete)]

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

        /// <summary>
        /// 获取课件分页列表
        /// </summary>
        /// <param name="sourcewarePagedRequest"></param>
        /// <returns></returns>
        [HttpPost(TrainPlanApiRoute.GetPagedList)]
        public async Task<TrainPlanPageViewResponse> GetPagedList([FromBody] TrainPlanPagedRequest sourcewarePagedRequest)
        {
            var trainTemplatePageViewResponse = await _trainTemplateService.GetPagedListAsync(sourcewarePagedRequest);

            return trainTemplatePageViewResponse as TrainPlanPageViewResponse;
        }


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

            return trainTemplateDto;
        }
    }
}
