<?php

namespace App\Http\Middleware;

use App\Services\LoginHistoryService;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class TrackUserActivity
{
    public function __construct(protected LoginHistoryService $loginHistory)
    {
    }

    public function handle(Request $request, Closure $next): Response
    {
        if ($request->user()) {
            $this->loginHistory->touch($request->user(), $request->session()->getId());
        }

        return $next($request);
    }
}
