<?php

namespace App\Framework\Smartlinks;

final readonly class TokenAction
{
    public function __construct(
        public string $name
    ) {
        if (empty($name)) {
            throw new \InvalidArgumentException('Action name cannot be empty');
        }

        if (!preg_match('/^[a-z_]+$/', $name)) {
            throw new \InvalidArgumentException('Action name must contain only lowercase letters and underscores');
        }
    }

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

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