<?php

namespace App\Service;

use Psr\Log\LoggerInterface;

/**
 * Service de tracking visiteurs pour les sites clients.
 */
class TrackingService
{
    public function __construct(
        private LoggerInterface $logger,
    ) {
    }

    /**
     * @param array<string, mixed> $metadata
     */
    public function trackPageView(string $siteId, string $url, string $visitorId, array $metadata = []): void
    {
        $this->logger->info('TrackingService::trackPageView', [
            'siteId' => $siteId,
            'url' => $url,
            'visitorId' => $visitorId,
            'metadata' => $metadata,
        ]);
    }

    /**
     * @param array<string, mixed> $metadata
     */
    public function trackEvent(string $siteId, string $eventName, string $visitorId, array $metadata = []): void
    {
        $this->logger->info('TrackingService::trackEvent', [
            'siteId' => $siteId,
            'eventName' => $eventName,
            'visitorId' => $visitorId,
            'metadata' => $metadata,
        ]);
    }

    /**
     * @return array<string, mixed>
     */
    public function getVisitorStats(string $siteId, \DateTimeInterface $startDate, \DateTimeInterface $endDate): array
    {
        return [
            'siteId' => $siteId,
            'period' => $startDate->format('Y-m-d').' - '.$endDate->format('Y-m-d'),
            'visitors' => 0,
            'uniqueVisitors' => 0,
            'bounceRate' => 0.0,
        ];
    }

    /**
     * @return array<string, mixed>
     */
    public function getPageViews(string $siteId, \DateTimeInterface $startDate, \DateTimeInterface $endDate): array
    {
        return [
            'siteId' => $siteId,
            'period' => $startDate->format('Y-m-d').' - '.$endDate->format('Y-m-d'),
            'totalViews' => 0,
            'pages' => [],
        ];
    }
}
