<?php

namespace Sibs\Sibs\Cron;

use Magento\Customer\Model\Session;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface as TransactionBuilderInterface;
use Magento\Sales\Model\Service\InvoiceService;
use Sibs\Sibs\Model\SibsConstants;
use Sibs\Sibs\Utils\SibsLog;

class CleanupCron
{
    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

    /**
     * @var OrderRepositoryInterface
     */
    private $orderRepository;

    /**
     * @var Session
     */
    private $session;

    /**
     * @var OrderSender
     */
    private $orderSender;

    /**
     * @var TransactionBuilderInterface
     */
    private $magentoTransactionBuilder;

    /**
     * @var InvoiceService
     */
    private $invoiceService;

    /**
     * @var InvoiceSender
     */
    private $invoiceSender;

    /**
     * @param SearchCriteriaBuilder $searchCriteriaBuilder
     * @param OrderRepositoryInterface $orderRepository
     * @param Session $session
     * @param OrderSender $orderSender
     * @param TransactionBuilderInterface $magentoTransactionBuilder
     * @param InvoiceService $invoiceService
     * @param InvoiceSender $invoiceSender
     */
    public function __construct(SearchCriteriaBuilder $searchCriteriaBuilder, OrderRepositoryInterface $orderRepository,
        Session $session, OrderSender $orderSender, TransactionBuilderInterface $magentoTransactionBuilder,
        InvoiceService $invoiceService, InvoiceSender $invoiceSender)
    {
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->orderRepository = $orderRepository;
        $this->session = $session;
        $this->orderSender = $orderSender;
        $this->magentoTransactionBuilder = $magentoTransactionBuilder;
        $this->invoiceService = $invoiceService;
        $this->invoiceSender = $invoiceSender;
    }

    /**
     * Execute Cron Function
     */
    public function execute()
    {
        SibsLog::setNameFile(SibsConstants::SIBS_LOG_CRON);

        SibsLog::debug('sibs cleanup cron begin');
        // TODO: Implement cron to cancel expired unpaid orders
        SibsLog::debug('sibs cleanup cron end');
    }
}
