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

namespace TravelCompanyBusinessLogic.OfficePackage
{
    public abstract class AbstractSaveToPdf
    {
        public void CreateTravelDoc(PdfInfo info)
        {
            CreatePdf(info);
            CreateParagraph(new PdfParagraph
            {
                Text = info.Title,
                Style = "NormalTitle"
            });
            CreateParagraph(new PdfParagraph
            {
                Text = $"с { info.DateAfter.ToShortDateString() } по { info.DateBefore.ToShortDateString() }", Style = "Normal"
            });
            CreateTable(new List<string> { "2cm", "2cm", "2cm", "5cm", "3cm", "3cm" });
            CreateRow(new PdfRowParameters
            {
                Texts = new List<string> { "Дата обеда", "Стоимость обеда", "Заказ", "Повар"},
                Style = "NormalTitle",
                ParagraphAlignment = PdfParagraphAlignmentType.Center
            });
            foreach (var travel in info.Traveles)
            {
                CreateRow(new PdfRowParameters
                {
                    Texts = new List<string> { travel.DateCreate.ToShortDateString(), "", "", ""},
                    Style = "Normal",
                    ParagraphAlignment = PdfParagraphAlignmentType.Left
                });

                // Вывод заказов для каждого обеда
                foreach (var excursion in travel.Excursions)
                {
                    CreateRow(new PdfRowParameters
                    {
                        Texts = new List<string> { "", "", excursion.Id.ToString(), ""},
                        Style = "Normal",
                        ParagraphAlignment = PdfParagraphAlignmentType.Left
                    });

                    // Вывод поваров для каждого заказа
                    foreach (var guide in excursion.GuideExcursions)
                    {
                        CreateRow(new PdfRowParameters
                        {
                            Texts = new List<string> { "", "", "", guide.Value.Surname },
                            Style = "Normal",
                            ParagraphAlignment = PdfParagraphAlignmentType.Left
                        });
                    }
                }
            }
            SavePdf(info);
        }
        public void CreateGuideDoc(PdfInfo info)
        {
            CreatePdf(info);
            CreateParagraph(new PdfParagraph
            {
                Text = info.Title,
                Style = "NormalTitle"
            });
            CreateParagraph(new PdfParagraph
            {
                Text = $"с {info.DateAfter.ToShortDateString()} по {info.DateBefore.ToShortDateString()}",
                Style = "Normal"
            });
            CreateTable(new List<string> { "2cm", "3cm", "2cm", "2cm", "2cm" });
            CreateRow(new PdfRowParameters
            {
                Texts = new List<string> { "Id повара", "ФИО повара", "Id обеда", "Дата начала обеда", "Дата окончания обеда" },
                Style = "NormalTitle",
                ParagraphAlignment = PdfParagraphAlignmentType.Center
            });
            foreach (var guide in info.Guides)
            {
                CreateRow(new PdfRowParameters
                {
                    Texts = new List<string> { guide.GuideId.ToString(), guide.FIO.ToString(), "", "", "" },
                    Style = "Normal",
                    ParagraphAlignment = PdfParagraphAlignmentType.Left
                });

                foreach (var travel in guide.Travels)
                {
                    CreateRow(new PdfRowParameters
                    {
                        Texts = new List<string> { "", "", travel.Id.ToString(), travel.DateStart.ToShortDateString(), travel.DateStart.ToShortDateString() },
                        Style = "Normal",
                        ParagraphAlignment = PdfParagraphAlignmentType.Left
                    });
                }
            }
            SavePdf(info);
        }
        protected abstract void CreatePdf(PdfInfo info);
        protected abstract void CreateParagraph(PdfParagraph paragraph);
        protected abstract void CreateTable(List<string> columns);
        protected abstract void CreateRow(PdfRowParameters rowParameters);
        protected abstract void SavePdf(PdfInfo info);
    }
}
