using Exam.Infrastructure.Data.Entity;
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 TrainTemplateController : BaseController
    {
        private readonly ITrainTemplateService _trainTemplateService;

        public TrainTemplateController(ITrainTemplateService trainTemplateService)
        {
            this._trainTemplateService = trainTemplateService;
        }

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

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

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

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

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

            return trainTemplatePageViewResponse as TrainTemplatePageViewResponse;
        }


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

            return trainTemplateDto;
        }

        /// <summary>
        /// 获取培训模版
        /// </summary>
        /// <param name="trainTemplatePagedRequest"></param>
        /// <returns></returns>
        [HttpGet(TrainTemplateApiRoute.GetList)]
        public async Task<List<TrainTemplateViewResponse>> GetList([FromQuery] TrainTemplatePagedRequest trainTemplatePagedRequest)
        {
            var result = await _trainTemplateService.GetListAsync(trainTemplatePagedRequest);

            return result.Item2;
        }
    }
}
