<?php

declare(strict_types=1);

namespace App\Handlers;

use Openguru\OpenCartFramework\Http\JsonResponse;
use Openguru\OpenCartFramework\Http\Request;
use Openguru\OpenCartFramework\Http\Response;
use Openguru\OpenCartFramework\TeleCartPulse\PulseIngestException;
use Openguru\OpenCartFramework\TeleCartPulse\TeleCartPulseService;

class TelemetryHandler
{
    private TeleCartPulseService $teleCartPulseService;

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

    /**
     * @throws PulseIngestException
     */
    public function ingest(Request $request): JsonResponse
    {
        $this->teleCartPulseService->handleIngest($request->json());

        return new JsonResponse([], Response::HTTP_NO_CONTENT);
    }
}
