using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.AppVersion;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// APP版本管理
    /// </summary>
    [Route("api/app/app-version")]
    [ApiController]
    [Authorize]
    public class AppVersionController : ControllerBase
    {
        private readonly ILogger<AppVersionController> _logger;
        private readonly IAppVersionRepository _appVersionRepository;

        public AppVersionController(ILogger<AppVersionController> logger, IAppVersionRepository appVersionRepository)
        {
            _logger = logger;
            _appVersionRepository = appVersionRepository;
        }


        /// <summary>
        /// app检查是否更新
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("get-version")]
        [AllowAnonymous]
        public async Task<AppVersion> GetAppVersion(AppVersionSearchRequest request)
        {
            return await _appVersionRepository.GetAppVersionAsync(request);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [HttpPost("app-list")]
        [AllowAnonymous]
        public async Task<IEnumerable<AppVersion>> GetAppVersionsAll()
        {
            return await _appVersionRepository.GetAppVersionsAsync();
        }

    }
}