<?php

declare(strict_types=1);

namespace App\Framework\Analytics\Queue;

use App\Framework\Queue\QueueProcessor;
use App\Framework\Analytics\Storage\AnalyticsStorageInterface;

final readonly class AnalyticsProcessor implements QueueProcessor
{
    public function __construct(
        private AnalyticsStorageInterface $storage
    ) {}

    public function canProcess(string $queue): bool
    {
        return $queue === 'analytics';
    }

    public function process(array $payload): void
    {
        $this->storage->store($payload);
    }

    public function failed(array $payload, \Throwable $exception): void
    {
        // Log failed analytics events
        error_log("Analytics processing failed: " . $exception->getMessage());
    }
}
