<?php
namespace Autogedal\AutogedalHelper\Model\Config\Source\Order;
use Magento\User\Model\ResourceModel\User\CollectionFactory as UserCollectionFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;

class Operator extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
    const OPERATORS_LIST  = 'changeorderstatus/operator_setting/options';

    protected $userCollectionFactory;
    protected $scopeConfig;

    public function __construct(
        UserCollectionFactory $userCollectionFactory,
        ScopeConfigInterface $scopeConfig
    ) {
        $this->userCollectionFactory = $userCollectionFactory;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * getAllOptions
     *
     * @return array
     */
    public function getAllOptions()
    {
        $adminUsers = [];
        $adminUserList = explode(',',$this->scopeConfig->getValue(self::OPERATORS_LIST));

        foreach ($this->userCollectionFactory->create() as $user) {
            if (in_array($user->getEmail(), $adminUserList)) {
                $adminUsers[] = [
                    'value' => $user->getId(),
                    'label' => $user->getName()
                ];
            }
        }

        return $adminUsers;
    }
}
