<?php
/**
 * Closed finding source filters for administration.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Admin;

/**
 * Maps user-facing sources to persisted object types.
 */
final class FindingSourceCatalog {
	const ALL      = 'all';
	const FILES    = 'files';
	const DATABASE = 'database';
	const PLUGINS  = 'plugins';

	/** @return string[] */
	public function sources(): array {
		return array( self::ALL, self::FILES, self::DATABASE, self::PLUGINS );
	}

	/** @return string */
	public function normalize( string $source ): string {
		return in_array( $source, $this->sources(), true ) ? $source : self::ALL;
	}

	/** @return string[] */
	public function types( string $source ): array {
		$mapping = array(
			self::ALL      => array(),
			self::FILES    => array( 'file' ),
			self::DATABASE => array( 'db_user', 'db_option', 'db_content' ),
			self::PLUGINS  => array( 'plugin' ),
		);
		$source  = $this->normalize( $source );
		return $mapping[ $source ];
	}

	/** @return string */
	public function label( string $source ): string {
		$labels = array(
			self::ALL      => __( 'All', 'localguard-scanner' ),
			self::FILES    => __( 'Files', 'localguard-scanner' ),
			self::DATABASE => __( 'Database', 'localguard-scanner' ),
			self::PLUGINS  => __( 'Plugins', 'localguard-scanner' ),
		);
		$source = $this->normalize( $source );
		return $labels[ $source ];
	}
}
