2026-09-30 09:47:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
namespace App\Cqs\Queries\Crm;
|
2026-09-30 09:47:10 +02:00
|
|
|
|
|
|
|
|
use App\Contracts\Query;
|
|
|
|
|
use App\Contracts\QueryInput;
|
|
|
|
|
use App\Services\CrmService;
|
|
|
|
|
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @implements \App\Contracts\Query<\App\Cqs\Queries\Crm\GetCrmCustomerQueryInput, \App\Cqs\Queries\Crm\GetCrmCustomerQueryOutput>
|
2026-09-30 09:47:10 +02:00
|
|
|
*/
|
|
|
|
|
final readonly class GetCrmCustomerQuery implements Query
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private CrmService $crmService,
|
|
|
|
|
private AppCustomerAuthService $authService,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __invoke(QueryInput $input): GetCrmCustomerQueryOutput
|
|
|
|
|
{
|
|
|
|
|
Assert::isAOf(
|
|
|
|
|
$input,
|
|
|
|
|
GetCrmCustomerQueryInput::class,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$hashcode = $input->fromHashcodeOrAuthenticatedUserHashcode ?? $this->authService->getCustomerAsMandatory()->hashcode;
|
|
|
|
|
|
|
|
|
|
$crmCustomer = $this->crmService->getCustomerFromHashCode(
|
|
|
|
|
$hashcode
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new GetCrmCustomerQueryOutput($crmCustomer);
|
|
|
|
|
}
|
|
|
|
|
}
|