<?php

declare(strict_types=1);

namespace App\Framework\Database\Cache\ValueObjects;

use App\Framework\Core\ValueObjects\Percentage;

/**
 * Query cache metrics value object
 */
final readonly class QueryCacheMetrics
{
    public function __construct(
        public int $hits,
        public int $misses,
        public Percentage $hitRatio
    ) {
    }

    public function getTotalRequests(): int
    {
        return $this->hits + $this->misses;
    }

    public function toArray(): array
    {
        return [
            'hits' => $this->hits,
            'misses' => $this->misses,
            'hit_ratio' => $this->hitRatio->format(),
            'total_requests' => $this->getTotalRequests(),
        ];
    }
}
