using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GxPress.Common.Tools;
using GxPress.Entity;
using GxPress.Repository.Interface.AppReport;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GxPress.Api.AppControllers
{
    /// <summary>
    /// App数据报表
    /// </summary>
    [Route("api/app/app-report")]
    [ApiController]
    [Authorize]

    public class AppReportController : ControllerBase
    {
        private readonly IAppReportRepository _appReportRepository;
        public AppReportController(IAppReportRepository appReportRepository)
        {
            _appReportRepository = appReportRepository;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<IEnumerable<Entity.AppReport>> GetAppReportList()
        {
            var result = await _appReportRepository.GetAppReportListAsync();
            var appReportList = result as AppReport[] ?? result.ToArray();
            foreach (var appReport in appReportList)
            {
                appReport.IocUrl = StringUtils.AddDomain(appReport.IocUrl);
            }

            return appReportList;
        }
    }
}