<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\MainBundle\Export;

class ExportConfigProcessor
{
    public function __construct(private readonly ExportManager $exportManager) {}

    /**
     * @return iterable<string, AggregatorInterface>
     */
    public function retrieveUsedAggregators(mixed $data): iterable
    {
        if (null === $data) {
            return [];
        }

        foreach ($data as $alias => $aggregatorData) {
            if ($this->exportManager->hasAggregator($alias) && true === $aggregatorData['enabled']) {
                yield $alias => $this->exportManager->getAggregator($alias);
            }
        }
    }

    /**
     * @return iterable<string, FilterInterface>
     */
    public function retrieveUsedFilters(mixed $data): iterable
    {
        if (null === $data) {
            return [];
        }

        foreach ($data as $alias => $filterData) {
            if ($this->exportManager->hasFilter($alias) && true === $filterData['enabled']) {
                yield $alias => $this->exportManager->getFilter($alias);
            }
        }
    }
}
