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

namespace PrecastConcretePlantBusinessLogic.OfficePackage
{
    public abstract class AbstractSaveToWord
    {
        public void CreateDocTable(WordInfoTable info)
        {
            CreateWord(info);

            CreateParagraph(new WordParagraph
            {
                Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
                TextProperties = new WordTextProperties
                {
                    Size = "24",
                    JustificationType = WordJustificationType.Center
                }
            });

            CreateTable(new()
            {
                ("Название", 3000),
                ("Дата", null),
                ("Адрес открытия", 4500),
            },
            info.Shops
            .Select(x => new List<string>
            {
                x.Name,
                Convert.ToString(x.DateOpening),
                x.Address,
            })
            .ToList());

            SaveWord(info);
        }

        public void CreateDoc(WordInfo info)
        {
            CreateWord(new() { FileName = info.FileName });

            CreateParagraph(new WordParagraph
            {
                Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
                TextProperties = new WordTextProperties
                {
                    Size = "24",
                    JustificationType = WordJustificationType.Center
                }
            });

            foreach (var reinforced in info.Reinforcedies)
            {
                CreateParagraph(new WordParagraph
                {
                    Texts = new List<(string, WordTextProperties)>
                    {
                        (reinforced.ReinforcedName      , new WordTextProperties { Size = "24", Bold = true}),
                        (" - цена: " + reinforced.Price.ToString(), new WordTextProperties { Size = "24" })
                    },
                    TextProperties = new WordTextProperties
                    {
                        Size = "24",
                        JustificationType = WordJustificationType.Both
                    }
                });
            }

            SaveWord(new());
        }

        protected abstract void CreateWord(WordInfoTable info);

        protected abstract void CreateParagraph(WordParagraph paragraph);

        protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows);
        protected abstract void SaveWord(WordInfoTable info);
    }
}
