<?php

declare(strict_types=1);

namespace App\Domain\SmartLink\ValueObjects;

use App\Framework\DateTime\Clock;
use App\Framework\Ulid\Ulid;

final readonly class SmartLinkId
{
    private function __construct(
        private string $value
    ) {
        if (! Ulid::isValid($value)) {
            throw new \InvalidArgumentException('Invalid SmartLink ID format');
        }
    }

    public static function generate(Clock $clock): self
    {
        $ulid = new Ulid($clock);

        return new self($ulid->__toString());
    }

    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;
    }
}
