<?php

namespace App\Jobs;

use App\Models\Setting;
use App\Services\Log\LogSaver;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class ArticleDiscoveryJob implements ShouldQueue
{
    use Queueable;

    public function __construct()
    {
        $this->onQueue('feed-discovery');
    }

    public function handle(LogSaver $logSaver): void
    {
        if (! Setting::isArticleProcessingEnabled()) {
            $logSaver->info('Article processing is disabled. Article discovery skipped.');

            return;
        }

        $logSaver->info('Starting article discovery for all active feeds');

        ArticleDiscoveryForFeedJob::dispatchForAllActiveFeeds();

        $logSaver->info('Article discovery jobs dispatched for all active feeds');
    }
}
