<?php

declare(strict_types=1);

namespace App\Framework\Cache\Events;

use App\Framework\Cache\CacheKey;
use App\Framework\Core\ValueObjects\Timestamp;

/**
 * Event fired when a cache hit occurs
 */
final readonly class CacheHit
{
    public function __construct(
        public CacheKey $key,
        public mixed $value,
        public int $valueSize,
        public Timestamp $timestamp
    ) {
    }

    /**
     * Create a new CacheHit event with the current timestamp
     */
    public static function create(CacheKey $key, mixed $value, int $valueSize = 0): self
    {
        return new self($key, $value, $valueSize, Timestamp::now());
    }
}
