using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Entity;
using GxPress.Entity.WorkProcess;
using GxPress.Repository.Interface;
using GxPress.Repository.Interface.WorkProcess;
using GxPress.Request.ProcessGroup;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 审批流程组
    /// </summary>
    [Route("api/admin/processGroup")]
    [ApiController]
    [Authorize]
    public class AdminProcessGroupController : Controller
    {
        private readonly IProcessGroupRepository _processGroupRepository;

        public AdminProcessGroupController(IProcessGroupRepository processGroupRepository)
        {
            _processGroupRepository = processGroupRepository;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ProcessGroup> Add([FromBody] ArticleGroupAddRequest request)
        {
            return await _processGroupRepository.AddAsync(request);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<IEnumerable<ProcessGroup>> GetList()
        {
            return await _processGroupRepository.GetListAsync();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<bool> Update(int id, [FromBody]ArticleGroupAddRequest request)
        {
            return await _processGroupRepository.UpdateAsync(id, request);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> Delete(int id)
        {
            return await _processGroupRepository.DeleteAsync(id);
        }

    }
}