using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YBDevice.Application.ReportInfo
{
    /// <summary>
    /// 统计报表
    /// </summary>
    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class ReportAppService : IDynamicApiController
    {
        private readonly IReportService _Service;
        public ReportAppService(IReportService Service)
        {
            _Service = Service;
        }

        /// <summary>
        /// 获取日统计数据
        /// </summary>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetListAsync(DateTime? starttime, DateTime? endtime)
        {
            var result=  await _Service.GetListAsync(starttime, endtime);
            var resultlist = new List<int>();
            var reglist = new List<int>();
            var devlist = new List<int>();
            var timelist = new List<string>();
            var incomelist = new List<int>();
            result.ForEach(x => {
                resultlist.Add(x.DayResultCnt);
                reglist.Add(x.DayRegCnt);
                devlist.Add(x.DayDevCnt);
                timelist.Add(x.Time);
                incomelist.Add(x.DayInCome);
            });
            return new ResultInfo(ResultState.SUCCESS, "success", new
            {
                resultlist = resultlist,
                timelist = timelist,
                devlist = devlist,
                incomelist = incomelist
            });
        }
        /// <summary>
        /// 获取指定设备统计数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<ResultInfo> GetDevListAsync(int id,DateTime? starttime, DateTime? endtime)
        {
            var result = await _Service.GetDevListAsync(id,starttime, endtime);
            var resultlist = new List<int>();
            var reglist = new List<int>();
            var devlist = new List<int>();
            var timelist = new List<string>();
            var incomelist = new List<int>();
            result.ForEach(x => {
                resultlist.Add(x.DayResultCnt);
                reglist.Add(x.DayRegCnt);
                devlist.Add(x.DayDevCnt);
                timelist.Add(x.Time);
                incomelist.Add(x.DayInCome);
            });
            return new ResultInfo(ResultState.SUCCESS, "success", new
            {
                resultlist = resultlist,
                timelist = timelist,
                devlist = devlist,
                incomelist = incomelist
            });
        }
    }
}
