<?php

namespace App\ValueObjects\Communications;

use Closure;

class PlaceholderDefinition
{
    public function __construct(
        public readonly string $token,
        public readonly ?string $appliesToType,
        public readonly Closure $resolver,
        public readonly ?string $fallback = null,
        public readonly ?string $description = null,
        public readonly bool $isHtml = false,
    ) {}

    public function matches(?string $appliesToType): bool
    {
        if ($this->appliesToType === null) {
            return true;
        }

        if ($appliesToType === null) {
            return false;
        }

        return is_a($appliesToType, $this->appliesToType, true);
    }
}
