<?php

declare(strict_types=1);

namespace App\Framework\View\Caching\Analysis;

class CacheabilityScore
{
    public bool $hasUserSpecificContent = false;

    public bool $hasCsrfTokens = false;

    public bool $hasTimestamps = false;

    public bool $hasRandomElements = false;

    public float $staticContentRatio = 0.0;

    public function getScore(): float
    {
        $score = $this->staticContentRatio;

        if ($this->hasUserSpecificContent) {
            $score -= 0.3;
        }
        if ($this->hasCsrfTokens) {
            $score -= 0.2;
        }
        if ($this->hasTimestamps) {
            $score -= 0.1;
        }
        if ($this->hasRandomElements) {
            $score -= 0.2;
        }

        return max(0, min(1, $score));
    }

    public function isCacheable(): bool
    {
        return $this->getScore() > 0.5;
    }
}
