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

namespace Hotline.Api.Controllers.Exam
{
    public class SourcewareCategoryController : BaseController
    {
        private readonly ISourcewareCategoryService _sourcewareCategoryService;
        public SourcewareCategoryController(ISourcewareCategoryService sourcewareCategoryService)
        {
            _sourcewareCategoryService = sourcewareCategoryService;
        }

        /// <summary>
        /// 新增课件类型
        /// </summary>
        /// <param name="sourcewareCategoryDto"></param>
        /// <returns></returns>
        [HttpPost(SourcewareCategoryApiRoute.Add)]
        public async Task Add([FromBody] AddSourcewareCategoryDto sourcewareCategoryDto)
        {
            await _sourcewareCategoryService.AddAsync(sourcewareCategoryDto, HttpContext.RequestAborted);
        }

        /// <summary>
        /// 修改课件类型
        /// </summary>
        /// <param name="sourcewareCategoryDto"></param>
        /// <returns></returns>
        [HttpPut(SourcewareCategoryApiRoute.Update)]
        public async Task Update([FromBody] UpdateSourcewareCategoryDto sourcewareCategoryDto)
        {
            await _sourcewareCategoryService.UpdateAsync(sourcewareCategoryDto,HttpContext.RequestAborted);
        }

        /// <summary>
        /// 删除课件类型
        /// </summary>
        /// <param name="entityQueryRequest"></param>
        /// <returns></returns>
        [HttpDelete(SourcewareCategoryApiRoute.Delete)]

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

        /// <summary>
        /// 获取树形列表
        /// </summary>
        /// <returns></returns>
        [HttpPost(SourcewareCategoryApiRoute.GetTreeList)]
        public async Task<List<SourcewareCategoryViewResponse>> GetTreeList([FromBody] SourcewareCategoryRequest sourcewareCategoryRequest)
        {
            var sourcewareCategorys = await _sourcewareCategoryService.GetTreeAsync(sourcewareCategoryRequest);

            return sourcewareCategorys;
        }

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

            return sourcewareCategoryDto;
        }

    }
}
