<?php

namespace App\Console\Commands;

use App\Jobs\ArticleDiscoveryJob;
use App\Models\Feed;
use App\Models\Setting;
use Illuminate\Console\Command;

class FetchNewArticlesCommand extends Command
{
    protected $signature = 'article:refresh';

    protected $description = 'Fetches latest articles';

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

            return self::SUCCESS;
        }

        if (! Feed::where('is_active', true)->exists()) {
            $this->info('No active feeds found. Article discovery skipped.');

            return self::SUCCESS;
        }

        ArticleDiscoveryJob::dispatch();

        return self::SUCCESS;
    }
}
