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

use EasyChat\Library\Messenger\AvitoHistorySyncService;

class MessengerAvitoHistorySyncJob {
    private $registry;

    public function __construct($registry) {
        $this->registry = $registry;
    }

    public function handle(array $payload): void {
        $result = (new AvitoHistorySyncService($this->registry))->syncByPayload($payload);
        if (empty($result['success'])) {
            throw new \Exception((string)($result['error'] ?? 'avito_history_sync_failed'));
        }
    }
}
