<?php
declare(strict_types=1);

namespace ROITheme\Admin\CustomCSSManager\Domain\ValueObjects;

use ROITheme\Shared\Domain\Exceptions\ValidationException;

/**
 * Value Object para tipo de carga CSS
 */
final class LoadType
{
    private const VALID_TYPES = ['critical', 'deferred'];

    private function __construct(
        private readonly string $value
    ) {}

    public static function fromString(string $value): self
    {
        if (!in_array($value, self::VALID_TYPES, true)) {
            throw new ValidationException(
                sprintf('LoadType inválido: %s. Valores válidos: %s',
                    $value,
                    implode(', ', self::VALID_TYPES)
                )
            );
        }
        return new self($value);
    }

    public static function critical(): self
    {
        return new self('critical');
    }

    public static function deferred(): self
    {
        return new self('deferred');
    }

    public function isCritical(): bool
    {
        return $this->value === 'critical';
    }

    public function isDeferred(): bool
    {
        return $this->value === 'deferred';
    }

    public function value(): string
    {
        return $this->value;
    }
}
