using ElectronicsShopBusinessLogic.OfficePackage;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;


namespace ElectronicsShopBusinessLogic.BusinessLogic
{
    public class ReportClientLogic : IReportClientLogic
    {
        private readonly IPaymeantStorage _paymeantstorage;
        private readonly AbstractSaveToExcelClient _saveToExcel;
        private readonly AbstractSaveToWordClient _saveToWord;

        public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient, IPaymeantStorage paymeantStorage) {
            _saveToExcel = abstractSaveToExcelClient;
            _saveToWord= abstractSaveToWordClient;
            _paymeantstorage = paymeantStorage;
        }
        public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
        {
            return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
                DateFrom = model.DateFrom,
                DateTo = model.DateTo
            }).Select(x => new ReportPaymeantsViewModel {
                ID = x.ID,
                DatePaymeant = x.DatePaymeant,
                OrderID = x.OrderID,
                ClientID = x.ClientID,
                SumPayment = x.SumPayment,
                PayOption = x.PayOption,
            }).ToList();
        }

        public void SavePaymeantToExcelFile(ReportBindingModel model)
        {
            _saveToExcel.CreateReport(new ExcelInfoClient
            {
                //FileName = model.ProductName,
                Title = "Список оплат",
                Paymeants = _paymeantstorage.GetFullList(),
            });
        }

        public void SavePaymeantToWordFile(ReportBindingModel model)
        {
            _saveToWord.CreateDoc(new WordInfoClient
            {
                //FileName = model.ProductName,
                Title = "Список оплат",
                ListPaymeant = _paymeantstorage.GetFullList(),
            }) ;
        }
    }
}