. */ declare(strict_types=1); namespace App\Services\InfoProviderSystem\DTOs; use App\Entity\Parts\Part; /** * Represents the search results for a single part from bulk info provider search. * It contains multiple search results, that match the part. */ readonly class BulkSearchPartResultsDTO { /** * @param Part $part The part that was searched for * @param BulkSearchPartResultDTO[] $searchResults Array of search results found for this part * @param string[] $errors Array of error messages encountered during search */ public function __construct( public Part $part, public array $searchResults = [], public array $errors = [] ) {} /** * Check if this part has any search results. */ public function hasResults(): bool { return !empty($this->searchResults); } /** * Check if this part has any errors. */ public function hasErrors(): bool { return !empty($this->errors); } /** * Get the number of search results for this part. */ public function getResultCount(): int { return count($this->searchResults); } public function getErrorCount(): int { return count($this->errors); } /** * Get search results sorted by priority (ascending). * @return BulkSearchPartResultDTO[] */ public function getResultsSortedByPriority(): array { $results = $this->searchResults; usort($results, static fn(BulkSearchPartResultDTO $a, BulkSearchPartResultDTO $b) => $a->priority <=> $b->priority); return $results; } }