using BarBusinessLogic.OfficePackage.HelperEnums;
using BarBusinessLogic.OfficePackage.HelperModels;

namespace BarBusinessLogic.OfficePackage
{
    public abstract class AbstractSaveToExcel
    {
        public void CreateReport(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 RepComp in Info.CocktailComponents)
            {
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "A",
                    RowIndex = RowIndex,
                    Text = RepComp.CocktailName,
                    StyleInfo = ExcelStyleInfoType.Text
                });
                
                RowIndex++;

                foreach (var (Component, Count) in RepComp.Components)
                {
                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "B",
                        RowIndex = RowIndex,
                        Text = Component,
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });

                    InsertCellInWorksheet(new ExcelCellParameters
                    {
                        ColumnName = "C",
                        RowIndex = RowIndex,
                        Text = Count.ToString(),
                        StyleInfo = ExcelStyleInfoType.TextWithBroder
                    });

                    RowIndex++;
                }

                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "A",
                    RowIndex = RowIndex,
                    Text = "Итого",
                    StyleInfo = ExcelStyleInfoType.Text
                });
                
                InsertCellInWorksheet(new ExcelCellParameters
                {
                    ColumnName = "C",
                    RowIndex = RowIndex,
                    Text = RepComp.TotalCount.ToString(),
                    StyleInfo = ExcelStyleInfoType.Text
                });
                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);
    }
}
