<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_MpPayPal
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
namespace Webkul\MpPayPal\Model\Seller;

class Onboarding
{

    /**
     * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection
     * @param \Webkul\MpPayPal\Helper\Data $helper
     */
    public function __construct(
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection,
        \Webkul\MpPayPal\Helper\Data $helper
    ) {
        $this->customerCollection = $customerCollection;
        $this->helper = $helper;
    }

    /**
     * manage on boarding
     *
     * @param array $resource
     * @return void
     */
    public function process($resource)
    {
        $this->helper->logDataInLogger('onboarding '.json_encode($resource));
        $collection = $this->customerCollection->create()->addAttributeToSelect('*')
                  ->addAttributeToFilter('mppaypal_submerchant_id', $resource['merchant_id'])
                  ->load();
        if ($collection->getSize()) {
            foreach ($collection as $customer) {
                $customer->setMppaypalMerchantStatus(1);
                $customer->save();
            }
        }
    }
}
