<?php
/**
 * Magetop
 *
 * @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\Plugin\Catalog\Model;

class Product
{
    /**
     * @var \Magetop\Quotesystem\Helper\Data
     */
    protected $quoteHelper;

    /**
     * @var \Magento\Framework\App\Request\Http
     */
    protected $request;

    /**
     * @param \Magento\Framework\App\Request\Http   $request
     * @param \Magetop\Quotesystem\Helper\Data       $quoteHelper
     */
    public function __construct(
        \Magento\Framework\App\Request\Http $request,
        \Magetop\Quotesystem\Helper\Data $quoteHelper
    ) {
        $this->_request = $request;
        $this->quoteHelper = $quoteHelper;
    }

    /**
     * Check whether the product type or stock allows to purchase the product
     *
     * @param  \Magento\Catalog\Model\Product   $subject
     * @param  [bool]                           $result
     * @return bool
     */
    public function afterIsAvailable(\Magento\Catalog\Model\Product $subject, $result)
    {
        $checkModuleEnabledOrNot = $this->quoteHelper->getModuleStatus();
        if ($this->_request->getFullActionName() == 'catalog_product_view' && $checkModuleEnabledOrNot == 1) {
            return true;
        }
        return $result;
    }
}
