<?php

namespace Functional\Streaks\Listeners;

use Functional\Streaks\Services\StreakService;
use Functional\Tracking\Events\WorkoutCompleted;

/**
 * Synchronise le streak du user à chaque séance d'entraînement terminée (couche tracking).
 */
class UpdateStreakOnWorkoutCompleted
{
    public function __construct(
        private readonly StreakService $streakService,
    ) {
    }

    public function handle(WorkoutCompleted $event): void
    {
        $session = $event->workoutSession;

        $this->streakService->recordActivity(
            $session->user,
            $session->started_at ?? now(),
            'workout',
            $session->id,
        );
    }
}
