using ComputerShopBusinessLogic.OfficePackage.HelperEnums;
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComputerShopBusinessLogic.OfficePackage
{
    public abstract class AbstractSaveToPdfImplementer
    {
        public void CreateDoc(PdfInfoImplementer info)
        {
            CreatePdf(info);
            CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
            CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
            CreateTable(new List<string> { "2cm", "2.5cm", "2cm", "2cm", "2cm", "4cm", "2.5cm", "3.5cm", "3.5cm", "2.5cm" });

            CreateRow(new PdfRowParameters
            {
                Texts = new List<string> { "ID заказа", "Дата заказа", "Сумма заказа", "Статус заказа", "ID заявки", "ФИО клиента", "Дата заявки", "Название сборки", "Категория сборки", "Цена сборки" },
                Style = "NormalTitle",
                ParagraphAlignment = PdfParagraphAlignmentType.Center
            });

            foreach (var order in info.Orders)
            {
                if (order.RequestsAssemblies.Count < 1)
                {
                    CreateRow(new PdfRowParameters
                    {
                        Texts = new List<string> {
                            order.OrderId.ToString(), order.DateCreateOrder.ToShortDateString(), order.OrderSum.ToString(), order.OrderStatus.ToString(),
                            "Заказ без заявок", "Неизвестно", "Неизвестно", 
                            "Неизвестно", "Неизвестно", "0"
                        }
                    });
                }
                foreach (var request in order.RequestsAssemblies)
                {
                    CreateRow(new PdfRowParameters
                    {
                        Texts = new List<string> { order.OrderId.ToString(), order.DateCreateOrder.ToShortDateString(), order.OrderSum.ToString(), order.OrderStatus.ToString(),
                            request.RequestId.ToString(), request.ClientFIO, request.DateRequest.ToShortDateString(),
                            string.IsNullOrEmpty(request.AssemblyName) ? "Сборка не привязана" : request.AssemblyName,
                            string.IsNullOrEmpty(request.AssemblyCategory) ? "Неизвестно" : request.AssemblyCategory,
                            request.AssemblyPrice.ToString()
                        }
                        //},
                        //Style = "Normal",
                        //ParagraphAlignment = PdfParagraphAlignmentType.Left
                    });
                }

            }
            SavePdf(info);
        }
        protected abstract void CreatePdf(PdfInfoImplementer info);
        protected abstract void CreateParagraph(PdfParagraph paragraph);
        protected abstract void CreateTable(List<string> columns);
        protected abstract void CreateRow(PdfRowParameters rowParameters);
        protected abstract void SavePdf(PdfInfoImplementer info);
    }
}