<?php

namespace FiloBlu\ActiveCampaign\Model\Config;

use FiloBlu\ConsentsManager\Api\ConsentTypeRepositoryInterface;
use Magento\Framework\Data\OptionSourceInterface;

class Options implements OptionSourceInterface
{

    /**
     * @var ConsentTypeRepositoryInterface
     */
    private $consentTypeRepository;

    /**
     * @param ConsentTypeRepositoryInterface $consentTypeRepository
     */
    public function __construct(ConsentTypeRepositoryInterface $consentTypeRepository)
    {
        $this->consentTypeRepository = $consentTypeRepository;
    }

    public function toOptionArray()
    {
        $fields = $this->consentTypeRepository->getList();
        $options = [];
        foreach ($fields->getItems() as $field) {
            $options[] = [
                'value' => $field->getId(),
                'label' => $field->getIdentifier()
            ];
        }
        return $options;
    }
}
