<?php

declare(strict_types=1);

namespace App\Framework\Cache\Events;

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

/**
 * Event fired when a value is set in cache
 */
final readonly class CacheSet
{
    public function __construct(
        public CacheKey $key,
        public mixed $value,
        public ?Duration $ttl,
        public bool $success,
        public int $valueSize,
        public Timestamp $timestamp
    ) {
    }

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