|
22 | 22 |
|
23 | 23 | namespace App\Services\InfoProviderSystem\DTOs; |
24 | 24 |
|
| 25 | +use App\Services\InfoProviderSystem\Providers\InfoProviderInterface; |
| 26 | + |
25 | 27 | /** |
26 | 28 | * Represents a mapping between a part field and the info providers that should search in that field. |
27 | 29 | */ |
28 | 30 | readonly class BulkSearchFieldMappingDTO |
29 | 31 | { |
| 32 | + /** @var string[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell']) */ |
| 33 | + public array $providers; |
| 34 | + |
30 | 35 | /** |
31 | 36 | * @param string $field The field to search in (e.g., 'mpn', 'name', or supplier-specific fields like 'digikey_spn') |
32 | | - * @param string[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell']) |
| 37 | + * @param string[]|InfoProviderInterface[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell']) |
33 | 38 | * @param int $priority Priority for this field mapping (1-10, lower numbers = higher priority) |
34 | 39 | */ |
35 | 40 | public function __construct( |
36 | 41 | public string $field, |
37 | | - public array $providers, |
| 42 | + array $providers = [], |
38 | 43 | public int $priority = 1 |
39 | 44 | ) { |
40 | 45 | if ($priority < 1 || $priority > 10) { |
41 | 46 | throw new \InvalidArgumentException('Priority must be between 1 and 10'); |
42 | 47 | } |
| 48 | + |
| 49 | + //Ensure that providers are provided as keys |
| 50 | + foreach ($providers as &$provider) { |
| 51 | + if ($provider instanceof InfoProviderInterface) { |
| 52 | + $provider = $provider->getProviderKey(); |
| 53 | + } |
| 54 | + if (!is_string($provider)) { |
| 55 | + throw new \InvalidArgumentException('Providers must be provided as strings or InfoProviderInterface instances'); |
| 56 | + } |
| 57 | + } |
| 58 | + unset($provider); |
| 59 | + $this->providers = $providers; |
43 | 60 | } |
44 | 61 |
|
45 | 62 | /** |
|
0 commit comments