<?php

namespace App\Service\Scraper;

use App\Entity\ContentSource;

class ScraperFactory
{
    private array $scrapers;

    public function __construct(iterable $scrapers)
    {
        $this->scrapers = iterator_to_array($scrapers);
    }

    public function createScraper(ContentSource $contentSource): ScraperInterface
    {
        foreach ($this->scrapers as $scraper) {
            if ($scraper->supports($contentSource->getScrapingType())) {
                return $scraper;
            }
        }
        throw new \InvalidArgumentException('Unsupported scraping type: '.$contentSource->getScrapingType());
    }
}
