using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Repository.Interface.Media;
using GxPress.Request.Media;
using GxPress.Result.Media;
using GxPress.Service.Interface.Media;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace GxPress.Api.AdminControllers
{
    [Route("api/admin/media")]
    [ApiController]
    [Authorize]
    public class AdminMediaController : Controller
    {
        private readonly IMediaRepository mediaRepository;
        private readonly ILoginContext _loginContext;
        private readonly IMediaService mediaService;
        public AdminMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService)
        {
            this.mediaRepository = mediaRepository;
            this._loginContext = _loginContext;
            this.mediaService = mediaService;
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<MediaResult> GetAsync(int id)
        {
            return await mediaRepository.GetAsync(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<bool> DeleteAsync(int id)
        {
            return await mediaRepository.DeleteAsync(id);
        }
        /// <summary>
        /// 添加媒体
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> InsertAsync(MediaResult result)
        {
            result.AdminId = _loginContext.AccountId;
            result.Creator = _loginContext.Name;
            return await mediaService.InsertAsync(result);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<bool> UpdateAsync(MediaResult result)
        {
            return await mediaRepository.UpdateAsync(result);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
        {
            return await mediaRepository.GetAllAsync(request);
        }
    }
}
