using Hotline.Share.Dtos.ExportWord;

namespace Hotline.Application.ExportWord
{
    public class WordExportService : IWordExportService
    {
        private readonly IWordExportProvider exportProvider;

        public WordExportService(IWordExportProvider _exportProvider)
        {
            exportProvider = _exportProvider;
        }

        public ExportByteWord TemplateCreateWord<T>(string templatePath, T data) where T : IWordExportTemplate
        {
            return exportProvider.ExportFromTemplate(templatePath, data);
        }

        public IEnumerable<ExportByteWord> TemplateCreateWord<T>(string templatePath, IEnumerable<T> data) where T : IWordExportTemplate
        {
            List<ExportByteWord> list = new();
            foreach (T datum in data)
            {
                list.Add(exportProvider.ExportFromTemplate(templatePath, datum));
            }

            return list;
        }

        public async Task<ExportByteWord> TemplateCreateWordAsync<T>(string templatePath, T data) where T : IWordExportTemplate
        {
            return await exportProvider.ExportFromTemplateAsync(templatePath, data);
        }

        public async Task<IEnumerable<ExportByteWord>> TemplateCreateWordAsync<T>(string templatePath, IEnumerable<T> data) where T : IWordExportTemplate
        {
            List<ExportByteWord> words = new();
            foreach (T obj in data)
            {
                T item = obj;
                List<ExportByteWord> fwWordList = words;
                fwWordList.Add(await exportProvider.ExportFromTemplateAsync(templatePath, item));
            }

            return words;
        }
    }
}
