using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Repository.Interface.SensitiveWord;
using GxPress.Request.SensitiveWord;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AdminControllers
{
    /// <summary>
    /// 敏感词
    /// </summary>
    [Route("api/admin/sensitive-word")]
    [ApiController]
    [Authorize]
    public class AdminSensitiveWordController : Controller
    {
        private readonly ISensitiveWordRepository _repository;
        private readonly ILoginContext _loginContext;

        public AdminSensitiveWordController(ISensitiveWordRepository _repository, ILoginContext _loginContext)
        {
            this._repository = _repository;
            this._loginContext = _loginContext;
        }
        /// <summary>
        /// 查询详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<Entity.tede2.SensitiveWord.SensitiveWord> GetAsync(int id)
        {
            return await _repository.GetAsync(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> DeleteAsync(int id)
        {
            return await _repository.DeleteAsync(id);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="note"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> InsertAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
        {
            note.AdminId = _loginContext.AccountId;
            note.Creator = _loginContext.Name;
            return await _repository.InsertAsync(note);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="note"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<bool> UpdateAsync(Entity.tede2.SensitiveWord.SensitiveWord note)
        {
            note.AdminId = _loginContext.AccountId;
            note.Creator = _loginContext.Name;
            return await _repository.UpdateAsync(note);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<PagedList<Entity.tede2.SensitiveWord.SensitiveWord>> GetAllAsync(SensitiveWordRequest request)
        {
            return await _repository.GetAllAsync(request);
        }
    }
}