using CCDCount.DLL.Tools;
using CCDCount.MODEL.AuditTrailModel;
using CCDCount.MODEL.SqlDataModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CCDCount.DLL.AuditTrail
{
    public class ValueChangeRecordClass
    {
        private byte[] imageBytes = null;
        public void GetRecordLogo(byte[] LogoPath)
        {
            imageBytes = LogoPath;
        }
        public string ValueChangeRecordToPDF(List<ErroeMesDataModelClass> ErrrorMes)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\ValueChangeRecord.pdf";
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("值更改", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.DateTime, o.UserID }).ToList(), "值更改");
            pDFGenerate.SavePDF();
            return SavePath;
        }


        public string ValueChangeRecordToPDFReColspan(List<ErroeMesDataModelClass> ErrorMes, List<string> ColSpanNames)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\ValueChangeRecord.pdf";
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("值更改", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.DateTime, o.UserID }).ToList(), ColSpanNames, "值更改");
            pDFGenerate.SavePDF();
            return SavePath;
        }

        public string ValueChangeRecordToPDF(List<ErroeMesDataModelClass> ErrorMes, string FileName)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\{FileName}.pdf";
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("值更改", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.DateTime, o.UserID }).ToList(), "值更改");
            pDFGenerate.SavePDF();
            return SavePath;
        }
    }
}
