<?php

namespace ArvaSeo\Actions;

use ArvaSeo\Services\Crawl;
use ArvaSeo\Services\Licensing;
class StartCrawler {
    private Crawl $crawl;

    private Licensing $licensing;

    public function __construct( Crawl $crawl, Licensing $licensing ) {
        $this->crawl = $crawl;
        $this->licensing = $licensing;
    }

    public function handle() : void {
        if ( !current_user_can( 'manage_options' ) ) {
            wp_send_json_error( [
                'message' => __( 'You are not allowed to start the crawl.', 'bulk-meta-editor' ),
            ], 403 );
        }
        check_ajax_referer( 'arva_seo_start_crawl', 'nonce' );
        if ( function_exists( 'arva_seo_fs' ) && arva_seo_fs()->is__premium_only() ) {
            $this->handle_premium__premium_only();
            return;
        }
        wp_send_json_error( [
            'message'     => $this->licensing->get_crawl_upgrade_message(),
            'upgrade_url' => $this->licensing->get_upgrade_url(),
        ], 403 );
    }

}
