<?php
/******************************************************************************
 *   ______                                                                   *
 *  /       \                                                                 *
 * /$$$$$$  | ________  __    __   ______    ______                           *
 * $$ |__$$ |/        |/  |  /  | /      \  /      \                          *
 * $$    $$ |$$$$$$$$/ $$ |  $$ |/$$$$$$  |/$$$$$$  |                         *
 * $$$$$$$$ |  /  $$/  $$ |  $$ |$$ |  $$/ $$    $$ |                         *
 * $$ |  $$ | /$$$$/__ $$ \__$$ |$$ |      $$$$$$$$/                          *
 * $$ |  $$ |/$$      |$$    $$/ $$ |      $$       |                         *
 * $$/   $$/ $$$$$$$$/  $$$$$$/  $$/        $$$$$$$/                          *
 *                                                                            *
 * @PROJECT    : 3D Preview Extension [Magetop.com]                           *
 * @AUTHOR     : Azure - Developer                                            *
 * @COPYRIGHT  : © 2019  Magetop.com                                          *
 * @LINK       : https://Magetop.com                                          *
 * @CREATED    :  10/01/2022                                                  *
 ******************************************************************************/

namespace Magetop\Advancepreview\Controller\Index;
use Magento\Framework\App\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
class TestEmail extends Action\Action
{
    /*protected $_resultPageFactory;

    protected $_modelDataFactory;
    protected $filesystem;
    protected $uploader;
    protected $_scopeConfig;
    protected $_transportBuilder;
    protected $inlineTranslation;
    public function __construct(
        Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        \Magento\MediaStorage\Model\File\UploaderFactory $uploader,
        \Magento\Framework\Filesystem $filesystem,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magetop\Advancepreview\Model\ReWrite\Mail\TransportBuilder $transportBuilder,
        \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
    )
    {
        $this->_resultPageFactory = $resultPageFactory;
        $this->uploader = $uploader;
        $this->filesystem = $filesystem;
        $this->_scopeConfig = $scopeConfig;
        $this->_transportBuilder = $transportBuilder;
        $this->inlineTranslation = $inlineTranslation;
        parent::__construct($context);
    }*/
    protected $jsonFactory;
    public function __construct(
        Context $context,
        \Magento\Framework\Controller\Result\JsonFactory $jsonFactory
    )
    {
        parent::__construct($context);
        $this->jsonFactory = $jsonFactory;
    }

    public function execute()
    {
        $response = ['tet'];
        /** @var \Magento\Wishlist\Model\Wishlist $wishlist*/

        $wishlist = $this->_objectManager->create('Magento\Wishlist\Model\Wishlist');
        $colletion = $wishlist->load(192)->getItemCollection();
        echo (string)$colletion->getSelect();
        echo $colletion->getSize();
        return $this->jsonFactory->create()->setData($response);
    }

    /*public function execute()
    {
        try{
            $request = $this->getRequest()->getParams();
            $tenFile = 'own_design.pdf';
            $base_media_path = $this->getMediaPath().'advancepreview/custom_previews/product_id_21/own_pdf/';
//            $data['myfile'] = $base_media_path.$tenFile;
            $fullFile = $base_media_path.$tenFile;
            $fileName = $tenFile;
            $templateVars = [
                'name'      => 'demo ',
                'message'   => 'test',
                'email'     => 'test test ',
                'telephone' => 'suppoer test test'
            ];

            $fromEmail= 'venkind.venkatesh@gmail.com'; //$this->getRequest()->getPostValue('email_address');
            $fromName = 'David Treu de ge';
            $newFile = 'md.pdf';

            $from = ['email' => $fromEmail, 'name' => $fromName];
            $this->inlineTranslation->suspend();

            $to =  $this->_scopeConfig->getValue(
                'contact/email/recipient_email',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE
            );

            $templateOptions = [
                'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
                'store' => 1
            ];

            if(isset($fileName)){
                $transport = $this->_transportBuilder->setTemplateIdentifier('sales_email_order_template')
                    ->setTemplateOptions($templateOptions)
                    ->setTemplateVars($templateVars)

                    ->setFrom($from)
                    ->addTo('maiuoc.k8c@gmail.com')
                    ->addAttachment(@file_get_contents($fullFile),$base_media_path.$newFile)
                    ->getTransport();
            }else{
                $transport = $this->_transportBuilder->setTemplateIdentifier('sales_email_order_template')
                    ->setTemplateOptions($templateOptions)
                    ->setTemplateVars($templateVars)
                    ->setFrom($from)
                    ->addTo('maiuoc.k8c@gmail.com')
                    ->getTransport();
            }


            $transport->sendMessage();
            $this->inlineTranslation->resume();
            echo 'Success '.$fullFile;

//            $this->messageManager->addSuccess(__('Form successfully submitted'));

//            $redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
//            $redirect->setUrl($this->_redirect->getRefererUrl());
//            return $redirect;

        }catch (\Exception $e) {
//            $this->messageManager->addError(__($e->getMessage()));
            echo $e->getMessage();
        }
//        $redirect->setUrl('index.php');
//        return $redirect;
    }*/
    protected function getMediaPath() {
         return $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();

    }
}
