52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Recipients;
|
|
|
|
final readonly class RecipientResolutionResult
|
|
{
|
|
/**
|
|
* @param array<int, array<string, mixed>> $recipients
|
|
* @param array<int, array<string, mixed>> $excluded
|
|
*/
|
|
public function __construct(
|
|
public array $recipients,
|
|
public array $excluded,
|
|
public int $selectedContactCount,
|
|
public int $selectedGroupCount,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<string, int>
|
|
*/
|
|
public function summary(): array
|
|
{
|
|
return [
|
|
'selected_contacts' => $this->selectedContactCount,
|
|
'selected_groups' => $this->selectedGroupCount,
|
|
'ready_numbers' => count($this->recipients),
|
|
'excluded_total' => count($this->excluded),
|
|
'opt_out' => $this->countExcludedReason('opt_out'),
|
|
'missing_phone' => $this->countExcludedReason('missing_phone'),
|
|
'invalid' => $this->countExcludedReason('invalid'),
|
|
'non_mobile' => $this->countExcludedReason('non_mobile'),
|
|
'duplicate' => $this->countExcludedReason('duplicate'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function excludedByReason(string $reason): array
|
|
{
|
|
return array_values(array_filter(
|
|
$this->excluded,
|
|
fn (array $entry): bool => ($entry['reason'] ?? null) === $reason,
|
|
));
|
|
}
|
|
|
|
private function countExcludedReason(string $reason): int
|
|
{
|
|
return count($this->excludedByReason($reason));
|
|
}
|
|
}
|