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

use EasyChat\Library\Messenger\InboundService;
use Exception;

class MessengerVkInboundJob {
    private $registry;

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

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