<?php
/**
 * Search-keyword extraction result.
 *
 * @package Affilun\Application\Product
 */

declare(strict_types=1);

namespace Affilun\Application\Product;

/**
 * Carries normalized product search keywords plus their generation source.
 */
final class SearchKeywordsExtractionResult {

	/**
	 * Normalized search keywords.
	 */
	private ?string $keywords;

	/**
	 * Generation source token.
	 */
	private ?string $source;

	/**
	 * @param string|null $keywords Search keywords, or null when unavailable.
	 * @param string|null $source   Generation source token.
	 */
	public function __construct( ?string $keywords, ?string $source ) {
		$normalizedKeywords = $keywords === null
			? null
			: trim( preg_replace( '/\s+/u', ' ', $keywords ) ?? $keywords );
		$this->keywords     = $normalizedKeywords === '' ? null : $normalizedKeywords;
		$this->source       = $source === null || trim( $source ) === '' ? null : trim( $source );
	}

	/**
	 * Search keywords.
	 */
	public function keywords(): ?string {
		return $this->keywords;
	}

	/**
	 * Generation source token.
	 */
	public function source(): ?string {
		return $this->source;
	}
}
