using System;
using System.IO;
using System.Text;
using OfficeOpenXml;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;

namespace Merchant_Email
{
    public class App
    {
        private readonly ILogger<App> _logger;
        private readonly IConfigurationRoot _config;

        public App(ILogger<App> logger, IConfigurationRoot config)
        {
            _logger = logger;
            _config = config;
        }

        public void Run()
        {
            // Let's test log levels:
            _logger.LogTrace("LogTrace");
            _logger.LogDebug("LogDebug");
            _logger.LogInformation("LogInformation");
            _logger.LogWarning("LogWarning");
            _logger.LogError("LogError");
            _logger.LogCritical("LogCritical");

            // TODO: Extract this to a service class
            // load from excel
            var filePath = @"C:/Log/Console/test.xlsx";
            FileInfo file = new FileInfo(filePath);

            using (ExcelPackage package = new ExcelPackage(file))
            {
                StringBuilder sb = new StringBuilder();
                ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
                int rowCount = worksheet.Dimension.Rows;
                int ColCount = worksheet.Dimension.Columns;

                var rawText = string.Empty;
                for (int row = 1; row <= rowCount; row++)
                {
                    for (int col = 1; col <= ColCount; col++)
                    {
                        rawText += worksheet.Cells[row, col].Value.ToString() + "\t";
                    }
                    rawText += "\r\n";
                }
                _logger.LogInformation(rawText);
            }
            Console.ReadKey();
        }
    }
}
