<?php

declare(strict_types=1);

namespace App\Framework\Database\Migration\ValueObjects;

use App\Framework\Core\ValueObjects\Percentage;

final readonly class MemoryThresholds
{
    public function __construct(
        public Percentage $warning,
        public Percentage $critical,
        public Percentage $abort
    ) {
        if ($this->warning->greaterThan($this->critical)) {
            throw new \InvalidArgumentException('Warning threshold cannot be higher than critical threshold');
        }

        if ($this->critical->greaterThan($this->abort)) {
            throw new \InvalidArgumentException('Critical threshold cannot be higher than abort threshold');
        }
    }

    public static function default(): self
    {
        return new self(
            warning: Percentage::from(75.0),  // 75% - Warning level
            critical: Percentage::from(85.0), // 85% - Critical level
            abort: Percentage::from(95.0)     // 95% - Abort migration
        );
    }

    public static function conservative(): self
    {
        return new self(
            warning: Percentage::from(60.0),
            critical: Percentage::from(70.0),
            abort: Percentage::from(80.0)
        );
    }

    public static function relaxed(): self
    {
        return new self(
            warning: Percentage::from(80.0),
            critical: Percentage::from(90.0),
            abort: Percentage::from(98.0)
        );
    }
}
