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

namespace TravelCompanyBusinessLogic.OfficePackage
{
    public abstract class AbstractSaveToExcel
    {
        public void CreateGuidesReport(ExcelInfo info)
        {
            CreateExcel(info);
            InsertCellInWorksheet(new ExcelCellParameters
            {
                ColumnName = "A",
                RowIndex = 1,
                Text = info.Title,
                StyleInfo = ExcelStyleInfoType.Title
            });
            MergeCells(new ExcelMergeParameters
            {
                CellFromName = "A1",
                CellToName = "C1"
            });
            uint rowIndex = 2;

            foreach (var reportGuideView in info.Guides)
            {
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "A",
                    RowIndex = rowIndex,
                    Text = $"Обед: {reportGuideView.Travel.TravelName}, {reportGuideView.Travel.DateStart}",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                MergeCells(new ExcelMergeParameters
                {
                    CellFromName = "A" + rowIndex,
                    CellToName = "E" + rowIndex
                });
                rowIndex++;

                foreach (var guide in reportGuideView.Guides)
                {
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "A",
                        RowIndex = rowIndex,
                        Text = guide.Surname,
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "B",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "C",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    MergeCells(new ExcelMergeParameters
                    {
                        CellFromName = "A" + rowIndex,
                        CellToName = "C" + rowIndex
                    });
                    rowIndex++;
                }
            }
            SaveExcel(info);
        }

        public void CreateExcursionsReport(ExcelInfo info)
        {
            CreateExcel(info);
            InsertCellInWorksheet(new ExcelCellParameters
            {
                ColumnName = "A",
                RowIndex = 1,
                Text = info.Title,
                StyleInfo = ExcelStyleInfoType.Title
            });
            MergeCells(new ExcelMergeParameters
            {
                CellFromName = "A1",
                CellToName = "C1"
            });
            uint rowIndex = 2;
            foreach (var excursionView in info.Excursions)
            {
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "A",
                    RowIndex = rowIndex,
                    Text = $"Продукт: Id: {excursionView.Tour.Id}. {excursionView.Tour.TourName}",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                MergeCells(new ExcelMergeParameters
                {
                    CellFromName = "A" + rowIndex,
                    CellToName = "E" + rowIndex
                });
                rowIndex++;

                foreach (var excursion in excursionView.Excursions)
                {
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "A",
                        RowIndex = rowIndex,
                        Text = $"Id: {excursion.Id}",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "B",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "C",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    MergeCells(new ExcelMergeParameters
                    {
                        CellFromName = "A" + rowIndex,
                        CellToName = "C" + rowIndex
                    });
                    rowIndex++;
                }
            }
            SaveExcel(info);
        }
        protected abstract void CreateExcel(ExcelInfo info);
        protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
        protected abstract void MergeCells(ExcelMergeParameters excelParams);
        protected abstract void SaveExcel(ExcelInfo info);
    }
}
