<?php
namespace EasyChat\Library\Queue\Jobs;

use EasyChat\Library\Crm\CrmSyncService;
use EasyChat\Library\Crm\CrmSyncException;
use EasyChat\Library\Queue\JobInterface;

final class CrmConversationSyncJob implements JobInterface {
    private $registry;
    public function __construct($registry) { $this->registry = $registry; }
    public function handle(array $payload): void {
        try {
            (new CrmSyncService($this->registry))->sync((int)($payload['connection_id'] ?? 0), (int)($payload['chat_id'] ?? 0), (int)($payload['message_id'] ?? 0));
        } catch (CrmSyncException $e) {
             
             
            if (!$e->isRetryable()) return;
            throw $e;
        }
    }
}
