<?php
namespace App\Salesforce\EventListener;
use App\Entity\ProUser;
use App\Event\EntityEvent;
use App\Salesforce\Api\ClientInterface;
class SalesForceReviewListener
{
public function __construct(private readonly ClientInterface $client)
{
}
public function onNewReview(EntityEvent $event): void
{
$review = $event->getEntity();
$user = $review->getUser();
if (null !== $user->getSfAccountId()) {
$sUser = (object) [
'Id' => $user->getSfAccountId(),
'Avis_client__c' => $review->getComment(),
'Note_client__c' => $review->getNote(),
];
$this->client->initiate();
$data = $this->client->upsert('Id', $sUser, 'Account');
$this->client->log('upsert', $data, $user instanceof ProUser ? 'Pro' : 'User');
}
}
}