<?php

declare(strict_types=1);

namespace App\Framework\GraphQL\Validation;

/**
 * Represents query complexity score
 *
 * Tracks total complexity and provides threshold checking
 */
final readonly class ComplexityScore
{
    public function __construct(
        public int $totalComplexity,
        public int $maxDepth,
        public int $fieldCount
    ) {
    }

    public static function zero(): self
    {
        return new self(0, 0, 0);
    }

    public function add(int $complexity, int $depth = 0): self
    {
        return new self(
            totalComplexity: $this->totalComplexity + $complexity,
            maxDepth: max($this->maxDepth, $depth),
            fieldCount: $this->fieldCount + 1
        );
    }

    public function exceedsThreshold(int $threshold): bool
    {
        return $this->totalComplexity > $threshold;
    }

    public function exceedsDepth(int $maxDepth): bool
    {
        return $this->maxDepth > $maxDepth;
    }
}
