<?php

declare(strict_types=1);

namespace App\Framework\Database\Cache\ValueObjects;

use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Core\ValueObjects\Percentage;

/**
 * Cache region metrics value object
 */
final readonly class RegionMetrics
{
    public function __construct(
        public string $name,
        public bool $enabled,
        public Duration $defaultTtl,
        public int $maxSize,
        public Percentage $efficiencyScore
    ) {
    }

    public function isPerformingWell(): bool
    {
        return $this->efficiencyScore->isAbove(Percentage::from(70.0));
    }

    public function needsOptimization(): bool
    {
        return $this->efficiencyScore->isBelow(Percentage::from(50.0));
    }

    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'enabled' => $this->enabled,
            'default_ttl_seconds' => $this->defaultTtl->toSeconds(),
            'max_size' => $this->maxSize,
            'efficiency_score' => $this->efficiencyScore->format(),
            'is_performing_well' => $this->isPerformingWell(),
            'needs_optimization' => $this->needsOptimization(),
        ];
    }
}
