<?php

declare(strict_types=1);

/**
 * SystemChecksPhaseService - Non-file system checks (reputation, users, content, etc.).
 *
 * Wraps the ScanOrchestrator's system checks phase. System checks run
 * BEFORE the round-robin file scanning loop (not as part of RR rotation)
 * because they can block on external services (e.g. reputation API).
 *
 * One check is executed per orchestrator tick to keep the UI responsive.
 *
 */

namespace SiteFort\Modules\Scanner\Queue\Phase;

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

class SystemChecksPhaseService implements PhaseServiceInterface {

    /** @var callable(array): bool */
    private $tick_fn;

    /** @var callable(): bool */
    private $is_complete_fn;

    /**
     * @param callable(array &$stats): bool $tick_fn       Runs the next pending system check.
     * @param callable(): bool              $is_complete_fn Returns true when all system checks are terminal.
     */
    public function __construct( callable $tick_fn, callable $is_complete_fn ) {
        $this->tick_fn        = $tick_fn;
        $this->is_complete_fn = $is_complete_fn;
    }

    public function tick( array &$stats ): bool {
        return ( $this->tick_fn )( $stats );
    }

    public function is_complete(): bool {
        return ( $this->is_complete_fn )();
    }

    public function get_phase_name(): string {
        // System checks run outside the RR loop; the name is for identification only.
        return 'system_checks';
    }
}
