<?php
/**
 * @author Aitoc Team
 * @copyright Copyright (c) 2020 Aitoc (https://www.aitoc.com)
 * @package Aitoc_PreOrders
 */

/**
 * Copyright © 2018 Aitoc. All rights reserved.
 * Developed by Alex Yakimovich
 */

namespace Aitoc\PreOrders\Setup;

use Aitoc\PreOrders\Setup\Operations\SetDefaultValuesForEmailSenderSettings;
use Aitoc\PreOrders\Setup\Operations\TransferLegacySettings;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;

class UpgradeData extends AbstractUpgrade implements UpgradeDataInterface
{
    /**
     * @var SetDefaultValuesForEmailSenderSettings
     */
    private $setDefaultValuesForEmailSenderSettingsOperation;

    /**
     * @var TransferLegacySettings
     */
    private $transferLegacySettingsOperation;

    /**
     * @param SetDefaultValuesForEmailSenderSettings $setDefaultValuesForEmailSenderSettingsOperation
     */
    public function __construct(
        SetDefaultValuesForEmailSenderSettings $setDefaultValuesForEmailSenderSettingsOperation,
        TransferLegacySettings $transferLegacySettingsOperation
    ) {
        $this->setDefaultValuesForEmailSenderSettingsOperation = $setDefaultValuesForEmailSenderSettingsOperation;
        $this->transferLegacySettingsOperation = $transferLegacySettingsOperation;
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $this->context = $context;
        if ($this->checkVersion('1.2.3')) {
            $this->setDefaultValuesForEmailSenderSettingsOperation->execute();
        }
        if ($this->checkVersion('1.2.5')) {
            $this->transferLegacySettingsOperation->execute();
        }
    }
}