using DocumentFormat.OpenXml.Spreadsheet;
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.BusinessLogicContracts;
using FurnitureAssemblyContracts.SearchModels;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace FurnitureAssemblyRestApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReportController : Controller
    {
        private readonly ILogger _logger;
        private readonly IReportWorkerLogic _reportWorkerLogic;
        public ReportController(ILogger<ReportController> logger, IReportWorkerLogic reportWorkerLogic)
        {
            _logger = logger;
            _reportWorkerLogic = reportWorkerLogic;
        }

        
        [HttpPost]
        public void CreateReportToDocx(ReportWorkerBindingModel model)
        {
            try
            {
                _reportWorkerLogic.SaveFurnitureModuleToWordFile(model);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка создания отчета");
                throw;
            }
        }
        [HttpPost]
        public void CreateReportToXlsx(ReportWorkerBindingModel model)
        {
            try
            {
                _reportWorkerLogic.SaveSetFurnitureModuleToExcelFile(model);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка создания отчета");
                throw;
            }
        }
    }
}
