<?php

declare(strict_types=1);


namespace Plugins\Neatstudio\AiModeration;

use App\Blog\Support\PluginManager;
use App\Blog\Support\PluginServiceProvider;

class ServiceProvider extends PluginServiceProvider
{
    protected function boot(PluginManager $manager): void
    {
        $this->loadViews(__DIR__.'/../views', 'plugin.ai-moderation');

        // 新评论创建后自动进入 AI 审核
        $manager->addAction('comment.created', function ($comment) {
            if (! app(\App\Blog\Services\LlmClient::class)->isConfigured()) {
                return;
            }

            if ((int) blog_setting('ai_moderation_enabled', 1) !== 1) {
                return;
            }

            if ($comment->status !== \App\Models\Comment::STATUS_PENDING) {
                return;
            }

            dispatch(new Jobs\AiModerateCommentJob($comment->id))->onQueue('ai');
        }, 10);
    }
}
