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

namespace Hotline.Api.Controllers.Exam
{
    public class SourcewaresController : BaseController
    {
        private readonly ISourcewareService _sourcewareService;

        public SourcewaresController(ISourcewareService sourcewareService)
        {
            _sourcewareService = sourcewareService;
        }

        /// <summary>
        /// 新增课件
        /// </summary>
        /// <param name="sourcewareDto"></param>
        /// <returns></returns>
        [HttpPost(SourcewareApiRoute.Add)]
        public async Task Add([FromBody] AddSourcewareDto sourcewareDto)
        {
            await _sourcewareService.AddAsync(sourcewareDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 修改课件
        /// </summary>
        /// <param name="sourcewareDto"></param>
        /// <returns></returns>
        [HttpPut(SourcewareApiRoute.Update)]
        public async Task Update([FromBody] UpdateSourcewareDto sourcewareDto)
        {
            await _sourcewareService.UpdateAsync(sourcewareDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 删除课件
        /// </summary>
        /// <param name="entityQueryRequest"></param>
        /// <returns></returns>
        [HttpDelete(SourcewareApiRoute.Delete)]
        public async Task Delete([FromBody] EntityQueryRequest entityQueryRequest)
        {
            await _sourcewareService.DeleteAsync(entityQueryRequest, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 获取课件分页列表
        /// </summary>
        /// <param name="sourcewarePagedRequest"></param>
        /// <returns></returns>
        [HttpPost(SourcewareApiRoute.GetPagedList)]
        public async Task<SourcewarePageViewResponse> GetPagedList([FromBody] SourcewarePagedRequest sourcewarePagedRequest)
        {
            var sourcewarePageViewResponse = await _sourcewareService.GetPagedListAsync(sourcewarePagedRequest);

            return sourcewarePageViewResponse as SourcewarePageViewResponse; 
        }

        /// <summary>
        /// 获取课件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet(SourcewareApiRoute.Get)]
        public async Task<SourcewareDto> Get(string id)
        {
            var sourcewareDto = await _sourcewareService.GetAsync(new EntityQueryRequest
            {
                Id = id
            });

            return sourcewareDto;
        }
    }
}
