using MWS.Domain.Common.DataExporting.Excel.EpPlus;
using MWS.Model.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MWS.Domain.Common.DataExporting
{
    public class HistoryAlertReportExcelExporter : EpPlusExcelExporterBase
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="userListDtos"></param>
        public void ExportToFile(string filePath, List<RealTimeAlertDto> userListDtos)
        {
            CreateExcelPackage(
              filePath,
              excelPackage =>
              {
                  var sheet = excelPackage.Workbook.Worksheets.Add("OperatorRecords");
                  sheet.OutLineApplyStyle = true;
                  AddHeader(
                      sheet,
                     "机构",
                     "类别",
                     "报警内容",
                     "触发时间",
                     "恢复时间"
                      );

                  AddObjects(
                      sheet, 2, userListDtos,
                      _ => _.MecType,
                      _ => _.AlertType,
                      _ => _.Message,
                      _ => _.TriggerTime,
                      _ => _.RecoverTime
                      );


                  var lastLoginTimeColumn = sheet.Column(4);
                  lastLoginTimeColumn.Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";

                  var creationTimeColumn = sheet.Column(5);
                  creationTimeColumn.Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";

                  for (var i = 1; i <= 5; i++)
                  {
                      sheet.Column(i).AutoFit();
                  }
              });
        }
    }
}
