<?php
/**
 * Database scan service.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Application\Scan;

use LocalGuardScanner\Detection\Database\DatabaseBatch;
use LocalGuardScanner\Detection\DetectorEngine;
use LocalGuardScanner\Domain\Detection\Evidence;

/**
 * Runs detectors over one normalized database batch.
 */
final class DatabaseScanService {
	/** @var DetectorEngine */
	private $engine;

	/** @param DetectorEngine $engine Database engine. */
	public function __construct( DetectorEngine $engine ) {
		$this->engine = $engine;
	}

	/**
	 * @param DatabaseBatch $batch Inventory batch.
	 * @return array<string,Evidence[]>
	 */
	public function inspect( DatabaseBatch $batch ) {
		$evidence = array();
		foreach ( $batch->items() as $item ) {
			$observations = $this->engine->inspect( $item );
			if ( ! empty( $observations ) ) {
				$evidence[ $item->locator() ] = $observations;
			}
		}
		return $evidence;
	}
}
