<?php

namespace ZenoChatbot\Services\Scheduler\Jobs;

use ZenoChatbot\Helper\Resources;
use ZenoChatbot\Services\Indexing\ContentIndexService;
use ZenoChatbot\Services\Indexing\Strategies\SiteMapIndex;

if (!defined('ABSPATH')) {
    exit;
}

class SitemapSyncJob
{
    public const LOCK_KEY = 'zeno_chatbot_ai_sitemap_sync_pending';

    public static function handle($payload = []): void
    {
        try {
            ContentIndexService::create(Resources::getBaseDirPath())
                ->sync(new SiteMapIndex(['chunk_size' => 50]));
        } finally {
            delete_transient(static::LOCK_KEY);
        }
    }
}
