<?php

declare(strict_types=1);

namespace App\Framework\MagicLinks;

final readonly class MagicLinkToken
{
    public function __construct(
        public string $value
    ) {
        if (empty($value)) {
            throw new \InvalidArgumentException('Token value cannot be empty');
        }

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

    public function equals(MagicLinkToken $other): bool
    {
        return hash_equals($this->value, $other->value);
    }

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