<?php
/**
 * Magetop Store
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */

namespace Magetop\Quotesystem\Controller\Adminhtml\Buyerquote;

use Magento\Framework\App\Action\Context;

class Printquote extends \Magento\Framework\App\Action\Action
{

    /**
     * Construct
     *
     * @param \Magento\Framework\App\Action\Context $context
     * @param \Magetop\Quotesystem\Model\QuotePdf    $quotePdf
     * @param \Psr\Log\LoggerInterface              $logger
     * @param \Magento\Backend\Model\Session        $backendSession
     */
    public function __construct(
        Context $context,
        \Magetop\Quotesystem\Model\QuotePdf $quotePdf,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Backend\Model\Session $backendSession
    ) {
        $this->quotePdf = $quotePdf;
        $this->logger = $logger;
        $this->backendSession = $backendSession;
        parent::__construct($context);
    }
    
    /**
     * Print quote action
     */
    public function execute()
    {
        $quoteId = $this->backendSession->getQuoteId();
        if ($quoteId) {
            try {
                $this->quotePdf->generatePdf($quoteId);
            } catch (\Exception $e) {
                $this->messageManager->addError(
                    __('Something went wrong.')
                );
                $this->logger->info($e->getMessage());
            }
        } else {
            $this->messageManager->addError(
                __('Invalid Quote Id.')
            );
        }
    }
}
