<?php

namespace Benhauer\Salesmanago\Model\Config\Source;

use \Benhauer\Salesmanago\Exception\SalesManagoException;
use \Benhauer\Salesmanago\Exception\UserAccessException;
use \Benhauer\Salesmanago\Model\User as UserModel;

use \SALESmanago\Factories\FactoryOrganizer;
use \SALESmanago\Provider\UserProvider;

class SelectCookieLifeTime implements \Magento\Framework\Option\ArrayInterface
{
    public $factoryOrganizer;
    public $model;

    public function __construct(
        FactoryOrganizer $factoryOrganizer,
        UserModel $model
    ) {
        $this->factoryOrganizer = $factoryOrganizer;
        $this->model = $model;
    }

    /**
     * @return array
     */
    public function toOptionArray()
    {
        $answer = [
            ['value' => 3, 'label' => '3'],
            ['value' => 12, 'label' => '12'],
            ['value' => 24, 'label' => '24'],
            ['value' => 48, 'label' => '48'],
            ['value' => 72, 'label' => '72'],
            ['value' => 100, 'label' => '100'],
            ['value' => 200, 'label' => '200'],
            ['value' => 300, 'label' => '300'],
            ['value' => 400, 'label' => '400'],
            ['value' => 500, 'label' => '500']
        ];

        return $answer;
    }

    /**
     * @return array - owners emails list for config select;
    */
    public function getOwnersEmailsList()
    {
        $answer = [];

        $integration = $this->factoryOrganizer->getInst(
            FactoryOrganizer::USER_ACCOUNT_C,
            UserProvider::initSettingsUser($this->model),
            $this->model
        );
        $response = $integration->listUsersByClient();

        if ($response['success'] && isset($response['users']))
        {
            foreach ($response['users'] as $user) {
                $answer[] = ['value' => $user, 'label' => $user];
            }
            return $answer;
        }

        return $answer;
    }
}
