<?php

declare(strict_types=1);

namespace App\Framework\Notification\Templates;

use App\Framework\Ulid\UlidGenerator;

/**
 * Template Identifier Value Object
 *
 * Unique identifier for notification templates
 */
final readonly class TemplateId
{
    public function __construct(
        public string $value
    ) {
        if (empty($value)) {
            throw new \InvalidArgumentException('Template ID cannot be empty');
        }

        if (strlen($value) < 16) {
            throw new \InvalidArgumentException('Template ID must be at least 16 characters');
        }
    }

    public static function generate(): self
    {
        return new self(UlidGenerator::generate());
    }

    public static function fromString(string $value): self
    {
        return new self($value);
    }

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

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }

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