<?php

declare(strict_types=1);

namespace TechnoArtisan\FilamentCms\Services;

use DateTime;
use Illuminate\Http\Request;

class TrackUserPageViews
{
    private const string DATETIME_FORMAT = 'Y-m-d H:i:s u';

    public function process(Request $request): void
    {
        $key = 'utd';

        if (!$request->session()->has($key)) {
            $utd = [];
        } else {
            $utd = $request->session()->get($key);
        }

        $utd[new DateTime()->format(self::DATETIME_FORMAT)] = $request->uri()->toStringable()->toString();

        $request->session()->put($key, $utd);
    }
}
