<?php

declare(strict_types=1);

/**
 * FileIndexPhaseService - File discovery phase.
 *
 * Wraps the ScanOrchestrator's file indexing (discovery) methods.
 * Delegates tick execution to the orchestrator via a callable so that
 * all complex discovery logic remains in ScanOrchestrator for now.
 * A future refactoring can migrate that logic here directly.
 *
 */

namespace SecurWP\Modules\Scanner\Queue\Phase;

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

class FileIndexPhaseService implements PhaseServiceInterface {

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

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

    /**
     * @param callable(array &$stats): bool $tick_fn       Runs one discovery batch; returns true if work done.
     * @param callable(): bool              $is_complete_fn Returns true when file index is complete.
     */
    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 {
        return 'discover';
    }
}
