<?php

namespace App\Services;

use App\Models\Topic;

class TopicBalancer
{
    public function getNextTopic(int $siteId): ?array
    {
        $topics = Topic::findActiveBySite($siteId);

        if (empty($topics)) {
            return null;
        }

        // Topics are already ordered by article_count ASC, RAND()
        // So the first one has the fewest articles (with random tiebreaker)
        return $topics[0];
    }
}
