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

namespace SoftwareInstallationBusinessLogic.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 package in info.Packages)
            {
                CreateParagraph(new WordParagraph
                {
                    Texts = new List<(string, WordTextProperties)>
                    {
                        (package.PackageName      , new WordTextProperties { Size = "24", Bold = true}),
                        (" - цена: " + package.Price.ToString(), new WordTextProperties { Size = "24" })
                    },
                    TextProperties = new WordTextProperties
                    {
                        Size = "24",
                        JustificationType = WordJustificationType.Both
                    }
                });
            }

            SaveWord(new());
        }

        /// <summary>
		/// Создание doc-файла
		/// </summary>
		/// <param name="info"></param>
        protected abstract void CreateWord(WordInfoTable info);

        /// <summary>
        /// Создание абзаца с текстом
        /// </summary>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        protected abstract void CreateParagraph(WordParagraph paragraph);

        /// <summary>
        /// Создание таблицы в файле
        /// </summary>
        /// <param name="nameAndWidthColumns">Строчка заголовок таблицы, определяет текст и ширину каждого столбца</param>
        /// <param name="rows">The rows.</param>
        protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows);

        /// <summary>
		/// Сохранение файла
		/// </summary>
		/// <param name="info"></param>
        protected abstract void SaveWord(WordInfoTable info);
    }
}
