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 = "Путешествие:",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "B",
                    RowIndex = rowIndex,
                    Text = "",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                MergeCells(new ExcelMergeParameters
                {
                    CellFromName = "A" + rowIndex,
                    CellToName = "B" + rowIndex
                });
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "C",
                    RowIndex = rowIndex,
                    Text = $"{reportGuideView.Travel.TravelName}",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "D",
                    RowIndex = rowIndex,
                    Text = "",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                MergeCells(new ExcelMergeParameters
                {
                    CellFromName = "C" + rowIndex,
                    CellToName = "D" + rowIndex
                });
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "E",
                    RowIndex = rowIndex,
                    Text = $"{reportGuideView.Travel.DateStart}",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "F",
                    RowIndex = rowIndex,
                    Text = "",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                MergeCells(new ExcelMergeParameters
                {
                    CellFromName = "E" + rowIndex,
                    CellToName = "F" + rowIndex
                });
                rowIndex++;
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "A",
                    RowIndex = rowIndex,
                    Text = "Гиды:",
                    StyleInfo = ExcelStyleInfoType.TextWithBroder
                });
                foreach (var guide in reportGuideView.Guides)
                {
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "B",
                        RowIndex = rowIndex,
                        Text = $"{guide.Surname} {guide.Name} {guide.Patronymic}",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "C",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "D",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "E",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "F",
                        RowIndex = rowIndex,
                        Text = "",
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });
                    MergeCells(new ExcelMergeParameters
                    {
                        CellFromName = "B" + rowIndex,
                        CellToName = "F" + 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);
    }
}
