<?php

namespace App\Support\Badges;

use InvalidArgumentException;

final class TagBadgeSpec
{
    /**
     * @var array<int, string>
     */
    private const ALLOWED_COLORS = [
        'gray',
        'primary',
        'info',
    ];

    public function __construct(
        public readonly string $label,
        public readonly string $color,
        public readonly ?string $icon = null,
        public readonly ?string $iconColor = null,
    ) {
        if (trim($this->label) === '') {
            throw new InvalidArgumentException('TagBadgeSpec label must be a non-empty string.');
        }

        if (! in_array($this->color, self::ALLOWED_COLORS, true)) {
            throw new InvalidArgumentException('TagBadgeSpec color must be one of: '.implode(', ', self::ALLOWED_COLORS));
        }

        if ($this->icon !== null && trim($this->icon) === '') {
            throw new InvalidArgumentException('TagBadgeSpec icon must be null or a non-empty string.');
        }

        if ($this->iconColor !== null && ! in_array($this->iconColor, self::ALLOWED_COLORS, true)) {
            throw new InvalidArgumentException('TagBadgeSpec iconColor must be null or one of: '.implode(', ', self::ALLOWED_COLORS));
        }
    }

    /**
     * @return array<int, string>
     */
    public static function allowedColors(): array
    {
        return self::ALLOWED_COLORS;
    }
}
