using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VeterinaryBusinessLogic.OfficePackage.Implements;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using VeterinaryContracts.SearchModels;
using VeterinaryBusinessLogic.OfficePackage;
using VeterinaryBusinessLogic.OfficePackage.HelperModels;

namespace VeterinaryBusinessLogic.BusinessLogic
{
    public class ReportLogicDoctor : IReportLogicDoctor
	{
		private readonly IMedicationStorage _medicationStorage;
		private readonly AbstractSaveToExcelDoctor _saveToExcel;
		private readonly AbstractSaveToWordDoctor _saveToWord;
		private readonly AbstractSaveToPdfDoctor _saveToPdf;

		public ReportLogicDoctor( IMedicationStorage medicationStorage,
			AbstractSaveToExcelDoctor saveToExcel, AbstractSaveToWordDoctor saveToWord, AbstractSaveToPdfDoctor saveToPdf)
		{
			_medicationStorage = medicationStorage;
			_saveToExcel = saveToExcel;
			_saveToWord = saveToWord;
			_saveToPdf = saveToPdf;
		}
		public void SavePurchasesToExcelFile(ReportPurchaseMedicationBindingModel model)
		{
			_saveToExcel.CreateReport(new ExcelInfoDoctor
			{
				FileName = model.FileName,
				Title = "Список покупок по медикаментам",
				PurchaseMedications = GetPurchaseMedications(model)
			});
		}

		public void SavePurchasesToWordFile(ReportPurchaseMedicationBindingModel model)
		{
			_saveToWord.CreateDoc(new WordInfoDoctor
			{
				FileName = model.FileName,
				Title = "Список покупок по медикаментам",
				PurchaseMedications = GetPurchaseMedications(model)
			});
		}

		public List<ReportPurchaseMedicationViewModel> GetPurchaseMedications(ReportPurchaseMedicationBindingModel model)
		{
			return _medicationStorage.GetReportMedicationPurchasesList(new() { medicationsIds = model.Medications });
		}
		public List<ReportDrugsVisitsViewModel> GetVisitsDrugs(ReportDrugsVisitsBindingModel model)
		{
			return _medicationStorage.GetReportDrugsVisits(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
		}

		public void SaveMedicationsToPdfFile(ReportDrugsVisitsBindingModel model)
		{
			_saveToPdf.CreateDoc(new PdfInfo
			{
				FileName = model.FileName,
				Title = "Список медикаментов",
				DateFrom = model.DateFrom!,
				DateTo = model.DateTo!,
				ReportDrugsVisits = GetVisitsDrugs(model)
			});

		}
	}
}
