<?php

namespace NewsletterBridge\Services\Feed;

use NewsletterBridge\Utils\Log;
use NewsletterBridge\Services\Feed\FeedGenerator;
use NewsletterBridge\Services\Feed\XMLFileManager;

/**
 * Responsabilità: Generazione file XML
 * Single Responsibility: Solo generazione XML
 */
class XMLGenerationService {
    
    private FeedGenerator $feedGenerator;
    private XMLFileManager $fileManager;
    
    public function __construct(
        FeedGenerator $feedGenerator,
        XMLFileManager $fileManager
    ) {
        $this->feedGenerator = $feedGenerator;
        $this->fileManager = $fileManager;
    }
    
    /**
     * Genera i file XML per la newsletter
     */
    public function generateXML(\stdClass $config, bool $generateFiles = true, int $site_id = null): array {
        $this->feedGenerator->resetUsedPosts();
        
        if (!$generateFiles) {
            return $this->feedGenerator->generateAllFeeds($config, true, $site_id);
        }
        
        $allFeeds = $this->feedGenerator->generateAllFeeds($config, false, $site_id);
        
        return $allFeeds;
    }
}
