<?php

declare(strict_types=1);

namespace SiteFort\Modules\Scanner\Service;

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

class QuarantineCleanupService {

    public const HOOK = 'sitefort_quarantine_purge';

    public static function register(): void {
        add_action( self::HOOK, [ __CLASS__, 'run' ] );

        if ( ! wp_next_scheduled( self::HOOK ) ) {
            wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', self::HOOK );
        }
    }

    public static function unregister(): void {
        wp_clear_scheduled_hook( self::HOOK );
    }

    public static function run(): void {
        $service = new QuarantineService();
        $service->purge_expired_items();
        $service->cleanup_stale_staged_items( time() - DAY_IN_SECONDS );
        $service->cleanup_old_purged_records( time() - ( 30 * DAY_IN_SECONDS ) );
    }
}
